Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Python : Built-in Functions, Dictionaries, If-Else

Answer Key

Q1. Write a Python program that takes two numbers as input from the user and displays their sum.

num1 = int(input("Enter the first number: "))


num2 = int(input("Enter the second number: "))
sum = num1 + num2
print("The sum is:", sum)

Q2. Write a Python program that prompts the user to enter their name and displays a personalized
greeting message.

name = input("Enter your name: ")


print("Hello,", name + "! Welcome to the program.")

Q7. What is the difference between the int() and float() functions in Python?

The int() and float() functions in Python are used to convert values to integers and floating-point
numbers, respectively. The int() function converts a value to an integer, truncating any decimal part, while
the float() function converts a value to a floating-point number, preserving the decimal part if present.

Q8. Explain the importance of built-in functions in Python programming.

Built-in functions in Python are essential as they provide ready-to-use functionality, eliminating the
need for writing complex code from scratch. They save time, improve code readability, and promote code
reuse.

Q9. Write a single program that contains all type conversion functions:
int(), str(), min(), max(), float(), eval(), abs(), type(), len(), range(), input()

# int()
print(int(3.14)) # Output: 3
print(int('42')) # Output: 42

# str()
print(str(123)) # Output: '123'
print(str(3.14)) # Output: '3.14'

You might also like