Class 8 Python worksheet
Class 8 Python worksheet
1
Question 1: Student Grade Calculator
A school awards grades to students based on the following criteria:
• If the percentage is 90 or above, the grade is A+.
• If the percentage is 80-89, the grade is A.
• If the percentage is 70-79, the grade is B.
• If the percentage is 60-69, the grade is C.
• If the percentage is 50-59, the grade is D.
• If the percentage is below 50, the grade is Fail.
Write a Python program that takes five subject marks as input, calculates the percentage, and
assigns a grade based on the given conditions.
Answer:
# Taking input for marks in five subjects
sub1 = float(input("Enter marks for Subject 1: "))
sub2 = float(input("Enter marks for Subject 2: "))
sub3 = float(input("Enter marks for Subject 3: "))
sub4 = float(input("Enter marks for Subject 4: "))
sub5 = float(input("Enter marks for Subject 5: "))
# Displaying results
print("\nTotal Marks:", total_marks)
print("Percentage:", percentage)
print("Grade:", grade)
Question 2: Electricity Bill Calculator
A power distribution company calculates the monthly electricity bill of a customer based on
the units consumed using the following tariff:
• Up to 100 units → ₹5 per unit
• 101 to 300 units → ₹8 per unit
• 301 to 500 units → ₹10 per unit
• Above 500 units → ₹12 per unit
Additionally, if the total bill exceeds ₹3000, a 5% surcharge is added.
Write a Python program that takes the customer's name and number of units consumed as
input and calculates the total bill.
2
Answer:
# Taking inputs
name = input("Enter customer name: ")
units = int(input("Enter number of units consumed: "))
3
discount = 0
# Displaying results
print("\nShopping Bill Summary")
print("Total Purchase Amount: ₹", total_amount)
print("Discount Applied: ₹", discount)
print("Final Payable Amount: ₹", final_amount)
Question No 4: Write a Python program that simulates a traffic signal system. The program
should:
• Take the traffic light color as input from the user (red, yellow, or green).
• Display the corresponding action:
o Red → "Stop! Wait for the light to change."
o Yellow → "Slow down! Get ready to stop."
o Green → "Go! You can proceed."
• If the user enters an invalid color, display a message saying "Invalid input! Please
enter red, yellow, or green."