Day 03 - Python Homework

Arithmetic Operators, User Input, and Conditionals

Practice Python to improve your coding skills. Use VS Code and create the files below. Run each program and check the output.

Remember to save your files with a .py extension and run them to see the output!

Assignment 01: Practicing Arithmetic Operators

We will practice using arithmetic operators (`+`, `-`, `*`, `/`, `%`, `//`, `**`) to work with numbers.

Objective:

Learn how arithmetic operators work in Python by applying them to simple fruit-related problems.

Tasks:

  • Create two variables: apples = 10 and mangoes = 4
  • Use arithmetic operators to:
    • Find the total fruits (addition)
    • Find the difference (subtraction)
    • Find the double apples (multiplication)
    • Find the apples per basket if divided into 2 baskets (division)
    • Try modulus (%) to see if fruits divide evenly
    • Try power (**) to square a number

Think About:

  • What happens when you divide and the result is not whole?
  • When would modulus (%) be useful in real life (e.g., sharing fruits)?

Assignment 02: User Input with Operators

Now let’s use user input to apply operators.

Objective:

Learn how to take input from the user and apply operators to calculate results.

Tasks:

  • Ask the user for two numbers (e.g., x and y)
  • Show the results of:
    • Sum (x + y)
    • Difference (x - y)
    • Product (x * y)
    • Division (x / y)
    • Compare which is greater (x > y, x < y)
    • Check if they are equal (x == y)

Think About:

  • What happens if the user enters 0 for y and you try to divide?
  • How do integer vs decimal inputs change results?

Assignment 03: Even or Odd Checker (If-Else)

Use if-else to check if a number is even or odd.

Objective:

Understand how conditions and the % operator work in decision-making.

Tasks:

  • Ask the user for a number.
  • If the number is divisible by 2 → print "Even Number"
  • Otherwise → print "Odd Number"

Think About:

  • What happens with negative numbers?
  • What happens with zero?

Assignment 04: Grade Classifier (If-Elif-Else)

Use if-elif-else to classify a student’s grade.

Objective:

Practice decision-making with multiple conditions.

Tasks:

  • Ask the user for marks (0–100).
  • Use conditions to classify:
    • 90 and above → "Grade A"
    • 75–89 → "Grade B"
    • 50–74 → "Grade C"
    • Below 50 → "Fail"

Think About:

  • What if the user enters more than 100 or less than 0?
  • How can you add more grades like A+ or D?

Assignment 05: Temperature Advisor (If-Elif-Else with User Input)

Use if-elif-else with user input to give weather advice.

Objective:

Combine user input with decision-making to provide different messages.

Tasks:

  • Ask the user to enter the temperature (°C).
  • Use conditions to give advice:
    • Less than 15 → "It’s Cold! Wear a jacket 🧥"
    • Between 15 and 30 → "Weather is Pleasant 🙂"
    • More than 30 → "It’s Hot! Stay hydrated 💧"

Think About:

  • How would advice change for very extreme temperatures (e.g., 45°C or -5°C)?
  • Can you extend it to show "Rainy" or "Snowy" with extra inputs?

If you need help

Post in the group with any of these problems:

Good luck and have fun coding!