0% found this document useful (0 votes)
8 views4 pages

Python Exercises

The document outlines a series of programming exercises designed to practice basic Python concepts, including arithmetic operations, unit conversion, logical operators, conditional expressions, and string methods. Each exercise provides specific instructions for user input and expected outputs, emphasizing the use of conditional statements and formatting. The exercises aim to enhance understanding of Python's functionality through practical application.

Uploaded by

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

Python Exercises

The document outlines a series of programming exercises designed to practice basic Python concepts, including arithmetic operations, unit conversion, logical operators, conditional expressions, and string methods. Each exercise provides specific instructions for user input and expected outputs, emphasizing the use of conditional statements and formatting. The exercises aim to enhance understanding of Python's functionality through practical application.

Uploaded by

watdalipe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JANUARY 16, 2026

EXERCISES:
Exercise 1: Basic Calculator
Goal: Practice if / elif / else with arithmetic operations

What to do:
1. Ask the user to enter the first number.
2. Ask the user to enter the second number.
3. Ask the user to select an operation from: + (addition), - (subtraction), * (multiplication), /
(division)
4. Convert both number inputs to floats.
5. Check and calculate:
 If operation is + , print the sum of the two numbers (rounded to 2 decimal places)
 If operation is - , print the difference (first number minus second number, rounded to 2
decimal places)
 If operation is * , print the product of the two numbers (rounded to 2 decimal places)
 If operation is / :
a. If the second number is 0, print “Error: Division by zero is not allowed”
b. Else, print the quotient (rounded to 2 decimal places)
 If operation is not one of the above, print “Error: Invalid operation selected”
 Use clear formatting for results (e.g., “5.00 + 3.00 = 8.00”)

Exercise 2 : Meter-Feet Unit Converter


Goal: Practice if / elif / else with unit conversion

What to do:
1. Ask user to enter measurement value (number).
2. Ask user to enter unit: M (meters) or F (feet).
3. Convert measurement to float.
4. Check and convert:
- If unit is M : Calculate feet (value × 3.28084) → Print “[value] meters = [converted] feet” (2
decimal places)
- If unit is F : Calculate meters (value × 0.3048) → Print “[value] feet = [converted] meters” (2
decimal places)
- Else: Print “Error: Invalid unit. Use ‘M’ or ‘F’”

EXERCISE 3: LOGICAL OPERATORS


1. and Operator Checker
Goal: Practice using the and logical operator

What to do:
1. Ask user to enter exam score (integer, 0-100).
2. Ask user if they completed all assignments (enter Y for yes, N for no).
3. Check:
- If (score ≥ 70) and (assignments are Y ):
Print “You passed the course!”
- Else:
Print “You did not pass the course.”

2. or Operator Checker
Goal: Practice using the or logical operator

What to do:
1. Ask user to enter current temperature (float).
2. Ask user if it is raining (enter Y for yes, N for no).
3. Check:
- If (temperature ≤ 15) or (raining is Y ):
Print “Bring a jacket or umbrella!”
- Else:
Print “No extra gear needed”
3. not Operator Checker
Goal: Practice using the not logical operator

What to do:
1. Ask user if the door is locked (enter Y for yes, N for no).
2. Check:
- If not (door is locked):
Print “Please lock the door before leaving!”
- Else:
Print “Door is secure. You may leave.”

EXERCISE 4: CONDITIONAL EXPRESSIONS


Goal: Practice using Python conditional expressions (ternary operators)

What to do:
1. Ask user to enter a test score (integer, 0-100).
2. Use a conditional expression to assign a grade:
- If score ≥ 75 → “Pass (Distinction)”
- If score ≥ 50 → “Pass”
- Else → “Fail”
3. Print the result: “Your score is [score] → Grade: [grade]”
Important::
- Use int(input()) for score input
- Implement using nested conditional expressions (no if/elif/else blocks)
- Syntax: value1 if condition1 else value2 if condition2 else value3

EXERCISE 5: STRING METHODS


What to do:
Enumerate the 47 built-in string methods in python or even define it (optional).

You might also like