0% found this document useful (0 votes)
2 views3 pages

Python Exercise

The document provides a series of Python exercises aimed at beginners, covering basic operations such as summing two numbers, calculating the area of a circle, converting Celsius to Fahrenheit, and checking data types. Each exercise includes example inputs and expected outputs to guide users in their coding practice. The exercises also touch on string manipulation, boolean evaluation, and simple calculator functions.

Uploaded by

Junaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python Exercise

The document provides a series of Python exercises aimed at beginners, covering basic operations such as summing two numbers, calculating the area of a circle, converting Celsius to Fahrenheit, and checking data types. Each exercise includes example inputs and expected outputs to guide users in their coding practice. The exercises also touch on string manipulation, boolean evaluation, and simple calculator functions.

Uploaded by

Junaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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'>.

You might also like