0% found this document useful (0 votes)
11 views7 pages

Grade 8 Python Solutions

This document contains solutions to various Python programming exercises for Grade 8, covering topics such as discount calculation, total and average marks, cab fare, grade determination, and more. Each solution includes code snippets that demonstrate how to implement the required functionality. The exercises also include practical applications like ATM simulation, electricity bill calculation, and generating Fibonacci series.

Uploaded by

Sakshi Gada
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)
11 views7 pages

Grade 8 Python Solutions

This document contains solutions to various Python programming exercises for Grade 8, covering topics such as discount calculation, total and average marks, cab fare, grade determination, and more. Each solution includes code snippets that demonstrate how to implement the required functionality. The exercises also include practical applications like ATM simulation, electricity bill calculation, and generating Fibonacci series.

Uploaded by

Sakshi Gada
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/ 7

Grade 8 - Python Programming Worksheet Solutions

1. Discount Calculation

price = float(input("Enter original price: "))

discount = price * 0.10

final_price = price - discount

print("Discount:", discount)

print("Final Price:", final_price)

2. Total, Average, Percentage

marks = [float(input(f"Enter marks for subject {i+1}: ")) for i in range(5)]

total = sum(marks)

average = total / 5

percentage = (total / 500) * 100

print("Total:", total, "Average:", average, "Percentage:", percentage)

3. Cab Fare

km = float(input("Enter distance travelled in km: "))

fare = 50 + 12 * km

print("Total Fare: Rs.", fare)

4. Grade Based on Percentage

percentage = float(input("Enter percentage: "))

if percentage >= 90:

grade = 'A'

elif percentage >= 80:

grade = 'B'
elif percentage >= 70:

grade = 'C'

elif percentage >= 60:

grade = 'D'

else:

grade = 'F'

print("Grade:", grade)

5. Even or Odd

num = int(input("Enter a number: "))

print("Even" if num % 2 == 0 else "Odd")

6. Age Category

age = int(input("Enter age: "))

if age < 12:

print("Child")

elif age <= 19:

print("Teenager")

else:

print("Adult")

7. Multiplication Table

n = int(input("Enter a number: "))

for i in range(1, 11):

print(f"{n} x {i} = {n*i}")

8. Sum of First n Natural Numbers


n = int(input("Enter a number: "))

total = sum(range(1, n+1))

print("Sum:", total)

9. Even Numbers Between 1 and 50

for i in range(2, 51, 2):

print(i, end=" ")

10. Sum Until 0 is Entered

total = 0

while True:

num = int(input("Enter a number (0 to stop): "))

if num == 0:

break

total += num

print("Sum:", total)

11. Palindrome Check

num = input("Enter a number: ")

print("Palindrome" if num == num[::-1] else "Not Palindrome")

12. Factorial

n = int(input("Enter a number: "))

fact = 1

while n > 1:

fact *= n

n -= 1
print("Factorial:", fact)

13. Electricity Bill

units = int(input("Enter units consumed: "))

if units <= 100:

bill = units * 3

elif units <= 200:

bill = 100*3 + (units - 100)*5

else:

bill = 100*3 + 100*5 + (units - 200)*10

print("Bill: Rs.", bill)

14. ATM Simulation

balance = 10000

while True:

print("1.Check 2.Withdraw 3.Deposit 4.Exit")

choice = int(input("Choose: "))

if choice == 1:

print("Balance: Rs.", balance)

elif choice == 2:

amount = int(input("Withdraw amount: "))

if amount <= balance:

balance -= amount

else:

print("Insufficient Balance")

elif choice == 3:

amount = int(input("Deposit amount: "))


balance += amount

elif choice == 4:

break

15. Prime Numbers in Range

import math

start = int(input("Start: "))

end = int(input("End: "))

for num in range(start, end+1):

if num > 1:

for i in range(2, int(math.sqrt(num)) + 1):

if num % i == 0:

break

else:

print(num, end=" ")

16. Reverse Number & Check Palindrome

num = input("Enter a number: ")

rev = num[::-1]

print("Reversed:", rev)

print("Palindrome" if num == rev else "Not Palindrome")

17. Factor Pairs

n = int(input("Enter a number: "))

for i in range(1, int(n**0.5) + 1):

if n % i == 0:

print(f"({i},{n//i})")
18. Train Ticket Pricing

age = int(input("Enter age: "))

price = 500

if age < 5:

final = 0

elif age <= 17:

final = price * 0.8

elif age >= 60:

final = price * 0.7

else:

final = price

print("Final Price: Rs.", final)

19. LCM

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

lcm = max(a, b)

while True:

if lcm % a == 0 and lcm % b == 0:

print("LCM:", lcm)

break

lcm += 1

20. Fibonacci Series

n = int(input("Enter number of terms: "))

a, b = 0, 1
for _ in range(n):

print(a, end=" ")

a, b = b, a + b

21. Armstrong Numbers in a Range

start = int(input("Enter start: "))

end = int(input("Enter end: "))

for num in range(start, end + 1):

sum_cubes = sum(int(d)**3 for d in str(num))

if sum_cubes == num:

print(num)

You might also like