Python Exercise
1. Sum of Two Numbers
Write a Python program that takes two numbers as input from the user, adds them, and prints
the result using an f-string.
Example Input:
5
3
Example Output:
The sum is 8.
2. Area of a Circle
Write a program that takes the radius of a circle as input, calculates the area (πr²), and prints
it. Use 3.14159 for π.
Example Input:
Example Output:
The area of the circle is 153.93804.
3. Convert Celsius to Fahrenheit
Write a program that takes a temperature in Celsius, converts it to Fahrenheit using the
formula:
F=(C×95)+32F = (C \times \frac{9}{5}) + 32
and prints the result.
Example Input:
25
Example Output:
25°C is equal to 77.0°F.
4. String Length Checker
Take a string as input and print its length.
Example Input:
Hello
Example Output:
The length of the string is 5.
5. Check Data Type
Write a program that takes user input and prints its data type.
Example Input:
42
Example Output:
The data type is <class 'str'>.
(Since input() always returns a string)
6. Add Integers from String Input
Take two numbers as input (in string format), convert them to integers, add them, and print
the sum.
Example Input:
"10"
"20"
Example Output:
The sum is 30.
7. Boolean Check
Take an input from the user and print whether it evaluates to True or False when converted
to a boolean.
Example Input:
0
Example Output:
The boolean value is False.
8. Check Even or Odd
Write a program that takes a number as input and checks if it is even or odd.
Example Input:
Example Output:
7 is an odd number.
9. Simple Calculator
Write a program that takes two numbers and an operator (+, -, *, /) as input, performs the
operation, and prints the result.
Example Input:
4
2
*
Example Output:
4 * 2 = 8
10. Convert String to Float
Take a string input representing a decimal number, convert it to a float, and print its type and
value.
Example Input:
"3.14"
Example Output:
The float value is 3.14 and its type is <class 'float'>.