Day 06 - Python Homework

Switch-Case Simulations and Calculators

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: Grade Calculator (Switch-Case)

To calculate the grade based on the marks obtained using match-case and display the grade with a suitable message.

Objective:

Learn how to use match-case conditions in Python to simulate the switch-case structure and calculate the grade based on the marks obtained.

Instructions:

  • Ask the user to enter the marks obtained in the exam (between 0 and 100).
  • Using match-case, calculate the grade based on the following rules:
    • If marks are ≥ 90, grade = "A+"
    • If marks are ≥ 75 and < 90, grade = "A"
    • If marks are ≥ 60 and < 75, grade = "B"
    • If marks are ≥ 50 and < 60, grade = "C"
    • If marks are < 50, grade = "F"
  • If the grade is "F", display: "Sorry, you failed! Please try again"
  • Otherwise, display: "Congratulations! You passed!"
  • Show the marks obtained and the final grade clearly.

Assignment 02: Discount Calculator (Switch-Case)

To calculate the discount on a shopping bill using match-case conditions and display the final bill amount after applying the discount.

Objective:

Learn how to calculate the discount on a shopping bill using match-case conditions in Python.

Instructions:

  • Ask the user to enter the total bill amount of the purchase.
  • Using match-case, calculate the discount based on the following rules:
    • If the bill is ≤ ₹500, discount = ₹0
    • If the bill is > ₹500 and ≤ ₹1000, discount = ₹50
    • If the bill is > ₹1000 and ≤ ₹5000, discount = ₹100
    • If the bill is > ₹5000, discount = ₹200
  • Subtract the discount from the total bill to calculate the final amount.
  • If the final amount is more than ₹5000, display: "You have a high bill amount!"
  • Otherwise, display: "Thank you for your purchase!"
  • Show the total bill, discount applied, and the final amount clearly.

If you need help

Post in the group with any of these problems:

Good luck and have fun coding!