Class VI
Simple programs to build a strong Python foundation.
Python practice questions for Classes VI, VII & VIII
Simple programs to build a strong Python foundation.
Booleans, if–else decisions and string operations.
Lists, for/while loops, modules and real-life programs.
break, continue, pass, functions and miscellaneous challenges.
Easy arithmetic, variables, input(), type(), expressions, and simple real-life calculations. No loops or conditional logic are required.
radius = float(input("Enter radius: "))
area = 3.14 * radius * radius
circumference = 2 * 3.14 * radius
print("Area =", area)
print("Circumference =", circumference)cows = 12
sheep = 18
total_legs = (cows * 4) + (sheep * 4)
print("Total legs on the farm =", total_legs)Output: 120
speed = 60
time = 4
distance = speed * time
print("Distance =", distance, "miles")Output: 240 miles
students = 24
notebooks_each = 7
total_notebooks = students * notebooks_each
print("Total notebooks =", total_notebooks)Output: 168
km = 42
metres = km * 1000
print("Total metres =", metres)Output: 42000 metres
apples = 15
apples_each = 3
friends = apples // apples_each
print("Total friends =", friends)Output: 5 friends
rahul_amount = 180
rahul_weight = 2
roshan_amount = 300
roshan_weight = 4
rahul_per_kg = rahul_amount / rahul_weight
roshan_per_kg = roshan_amount / roshan_weight
print("Rahul: ₹", rahul_per_kg, "per kg")
print("Roshan: ₹", roshan_per_kg, "per kg")Rahul = ₹90/kg, Roshan = ₹75/kg.
cost_6 = 210
cost_1 = cost_6 / 6
cost_4 = cost_1 * 4
print("Cost of 4 cans =", cost_4, "INR")Output: ₹140
m1, m2, m3, m4 = 36, 35, 50, 55
mean = (m1 + m2 + m3 + m4) / 4
print("Mean score =", mean)Output: 44
y = -2
value = 3*y*(2*y - 7) - 3*(y - 4) - 63
print(value)Output: 21
d1 = 16
area = 240
d2 = area / (0.5 * d1)
print("Second diagonal =", d2, "cm")Output: 30 cm
length = 80
width = 30
height = 40
front_back = 2 * length * height
side_walls = 2 * width * height
wall_area = front_back + side_walls
print("Area needed =", wall_area, "sq. cm")Output: 8800 cm²
r = 7
h = 3
tsa = round(2 * 3.14 * r * (r + h), 0)
print("Sheet needed =", tsa, "sq. metre")Output: approximately 440 m².
print(((8**-1) * (5**3)) / (2**-4))Output: 250.0
print(19 ** 0.5)Output: approximately 4.3589.
name = input("Enter your name: ")
age = int(input("Enter your age: "))
current_year = int(input("Enter the current year: "))
year_100 = current_year + (100 - age)
print(name, "will turn 100 in", year_100)input().value = input("Enter anything: ")
print(type(value))input() returns a string unless you convert it.
A school-fee program could store values such as student_name, monthly_fee, and months. Variables make it possible to store information and use it later in calculations or output.
a = 10
b = 8
c = 8.7
result = a + b + c
print(result)Output: 26.7. Many other correct combinations are possible.
Meaningful variable names make a program easier to read, understand, debug, and modify. For example, total_marks is much clearer than a vague name such as x.
You could measure how many seconds it takes a student to leave the classroom after the bell rings and store it in a variable such as exit_time. You could also count how many times a word is repeated during a conversation.
Python normally executes statements from top to bottom. A command can only affect statements that run after it. For example, changing a turtle's speed after all movement commands have already finished will not change the speed of those earlier movements.
Boolean expressions, comparisons, basic if/elif/else, and simple string operations.
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")word = input("Enter a word: ")
if len(word) % 2 == 0:
print("The word has an even number of characters.")
else:
print("The word has an odd number of characters.")language = input("Enter language code (EN/ES/FR): ").upper()
if language == "EN":
print("Hello")
elif language == "ES":
print("Hola")
elif language == "FR":
print("Bonjour")
else:
print("Language not available")num = int(input("Enter a number: "))
if num % 5 == 0:
print("Hello")
else:
print("Bye")A Boolean is a value that is either True or False. Comparison expressions produce Boolean results.
print(10 > 5) # True
print(3 == 7) # Falseword = input("Enter a word: ")
print("Uppercase:", word.upper())
print("Lowercase:", word.lower())
print("Reversed:", word[::-1])word = input("Enter a word: ")
if word == word[::-1]:
print("Palindrome")
else:
print("Not a palindrome")weather = input("Enter today's weather: ").lower()
if weather == "rainy":
print("Carry an umbrella.")
elif weather == "sunny":
print("Wear a cap and carry water.")
elif weather == "cold":
print("Wear warm clothes.")
else:
print("Have a nice day!")a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
if a > b:
print("Greatest number =", a)
elif b > a:
print("Greatest number =", b)
else:
print("Both numbers are equal.")age = int(input("Enter your age: "))
if age < 12 or age >= 60:
print("Free ticket!")
else:
print("Regular ticket required.")a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
if a >= b and a >= c:
largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c
print("Largest number =", largest)a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Before swapping:")
print("a =", a)
print("b =", b)
temp = a
a = b
b = temp
print("After swapping:")
print("a =", a)
print("b =", b)balance = 10000
print("1. Check Balance")
print("2. Deposit")
print("3. Withdraw")
choice = int(input("Enter your choice: "))
if choice == 1:
print("Balance =", balance)
elif choice == 2:
amount = int(input("Enter deposit amount: "))
balance = balance + amount
print("Updated Balance =", balance)
elif choice == 3:
amount = int(input("Enter withdrawal amount: "))
if amount <= balance:
balance = balance - amount
print("Updated Balance =", balance)
else:
print("Insufficient Balance")
else:
print("Invalid Choice")name = input("Enter student name: ")
sub1 = int(input("Enter marks of Subject 1: "))
sub2 = int(input("Enter marks of Subject 2: "))
sub3 = int(input("Enter marks of Subject 3: "))
sub4 = int(input("Enter marks of Subject 4: "))
sub5 = int(input("Enter marks of Subject 5: "))
total = sub1 + sub2 + sub3 + sub4 + sub5
percentage = total / 5
print("\nStudent Name:", name)
print("Total Marks:", total)
print("Percentage:", percentage)
if percentage >= 90:
print("Grade: A+")
elif percentage >= 80:
print("Grade: A")
elif percentage >= 70:
print("Grade: B")
elif percentage >= 60:
print("Grade: C")
elif percentage >= 50:
print("Grade: D")
else:
print("Grade: Fail")print("1. Rectangle")
print("2. Circle")
print("3. Triangle")
print("4. Square")
choice = int(input("Enter your choice: "))
if choice == 1:
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
print("Area =", l * b)
elif choice == 2:
r = float(input("Enter radius: "))
print("Area =", 3.14 * r * r)
elif choice == 3:
b = float(input("Enter base: "))
h = float(input("Enter height: "))
print("Area =", 0.5 * b * h)
elif choice == 4:
s = float(input("Enter side: "))
print("Area =", s * s)
else:
print("Invalid Choice")print("1. Arts")
print("2. Commerce")
print("3. Diploma Engineering")
print("4. PCB")
print("5. PCM")
choice = int(input("Enter your choice: "))
percentage = float(input("Enter your percentage: "))
if choice == 1:
if percentage >= 50:
print("You are eligible for Arts.")
else:
print("You are not eligible for Arts.")
elif choice == 2:
if percentage >= 60:
print("You are eligible for Commerce.")
else:
print("You are not eligible for Commerce.")
elif choice == 3:
if percentage >= 65:
print("You are eligible for Diploma Engineering.")
else:
print("You are not eligible for Diploma Engineering.")
elif choice == 4:
if percentage >= 75:
print("You are eligible for PCB.")
else:
print("You are not eligible for PCB.")
elif choice == 5:
if percentage >= 80:
print("You are eligible for PCM.")
else:
print("You are not eligible for PCM.")
else:
print("Invalid Choice")Lists and list methods, for and while loops, compound conditions using and/or/in, and the random and time modules. A few supplied function/lambda questions are retained as challenge items.
len() and a for loop.items = ["Python", "AI", "HTML", "Computer"]
for item in items:
print(item, "has", len(item), "characters")["socks", "tshirt", "pajamas"] to the end of gift_list as one nested list item.gift_list = ["socks", "4K drone", "wine", "jam"]
gift_list.append(["socks", "tshirt", "pajamas"])
print(gift_list)"broccoli" from the list using both .index() and .pop().lst = ["milk", "banana", "broccoli"]
position = lst.index("broccoli")
lst.pop(position)
print(lst)for loop to print “Hello!” followed by each name in the list.names = ["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]
for name in names:
print("Hello!,", name)"Civilization" by increasing a counter inside a for loop.text = "Civilization"
c = 0
for i in text:
c = c + 1
print(c)The loop adds 1 a total of 12 times.
for loop to append the square of each number from lst1 into lst2.lst1 = [3, 7, 6, 8, 9, 11, 15, 25]
lst2 = []
for num in lst1:
lst2.append(num ** 2)
print(lst2)for loop with an if statement to create a new list containing only positive numbers.lst1 = [111, 32, -9, -45, -17, 9, 85, -10]
lst2 = []
for num in lst1:
if num > 0:
lst2.append(num)
print(lst2)for loop.for i in range(1, 11):
print(i)for loop.for i in range(2, 22, 2):
print(i)for loop.for i in range(1, 21, 2):
print(i)for i in range(20, 0, -2):
print(i)total = 0
for i in range(10):
num = float(input("Enter number: "))
total = total + num
print("Average =", total / 10)for loop.num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial = factorial * i
print("Factorial =", factorial)while loop.num = int(input("Enter a number: "))
factorial = 1
i = 1
while i <= num:
factorial *= i
i += 1
print("Factorial =", factorial)while loop.terms = int(input("How many terms? "))
a, b = 0, 1
count = 0
while count < terms:
print(a)
a, b = b, a + b
count += 1while loop.num = int(input("Enter a positive integer: "))
total = 0
while num:
digit = num % 10
total += digit
num //= 10
print("Sum of digits =", total)while loop.num = int(input("Enter a positive integer: "))
product = 1
while num:
digit = num % 10
product *= digit
num //= 10
print("Product of digits =", product)while loop.num = int(input("Enter a positive integer: "))
reverse = 0
while num > 0:
digit = num % 10
reverse = reverse * 10 + digit
num //= 10
print("Reversed number =", reverse)while loop.num = int(input("Enter a number: "))
i = 1
while i <= 10:
print(num, "x", i, "=", num * i)
i += 1while loop.text = input("Enter a word: ")
left = 0
right = len(text) - 1
is_palindrome = True
while left < right:
if text[left] != text[right]:
is_palindrome = False
break
left += 1
right -= 1
if is_palindrome:
print("Palindrome")
else:
print("Not a palindrome")while loop.num = int(input("Enter a number: "))
i = 2
is_prime = num > 1
while i * i <= num and is_prime:
if num % i == 0:
is_prime = False
i += 1
if is_prime:
print("Prime")
else:
print("Not prime")while loop.text = input("Enter text: ")
i = 0
count = 0
while i < len(text):
if text[i] != " ":
count += 1
i += 1
print("Characters excluding spaces =", count)while loop.num = int(input("Enter a positive number: "))
while num != 1:
print(num, end=" ")
if num % 2 == 0:
num //= 2
else:
num = 3 * num + 1
print(1)import random
secret = random.randint(1, 100)
guess = 0
while guess != secret:
guess = int(input("Guess a number from 1 to 100: "))
if guess < secret:
print("Too low!")
elif guess > secret:
print("Too high!")
else:
print("Correct!")fizz = 0
buzz = 0
fizzbuzz = 0
for num in range(1, 1000):
if num % 3 == 0 and num % 5 == 0:
fizzbuzz += 1
elif num % 5 == 0:
fizz += 1
elif num % 3 == 0:
buzz += 1
print("Fizz =", fizz)
print("Buzz =", buzz)
print("FizzBuzz =", fizzbuzz)Counts: Fizz = 133, Buzz = 267, FizzBuzz = 66.
in keyword to check whether a student name is present in a list.students = ["Aman", "Sara", "Riya", "Kabir"]
name = input("Enter a name: ")
if name in students:
print("Student found")
else:
print("Student not found")or keyword to check whether a user entered “yes” or “y”.choice = input("Continue? ").lower()
if choice == "yes" or choice == "y":
print("Continuing...")
else:
print("Stopped.")time module to create a simple 5-second countdown.import time
for i in range(5, 0, -1):
print(i)
time.sleep(1)
print("Go!")for loop become infinite? Where might a for loop be useful in real life?A normal for loop over a finite list, string, or range() ends automatically, so it is usually not infinite. A for loop is useful whenever an action must repeat for each item—for example, printing every student's name, checking each mark in a list, or sending the same instruction to several devices.
Extra programs for students who are ready to explore beyond the core Class VI–VIII sequence.
books = ["Maths", "Science", "Python", "English", "AI"]
for book in books:
if book == "Python":
print("Python book found!")
breakattempts = ["1111", "2468", "1234", "9999"]
for pin in attempts:
if pin == "1234":
print("Access Granted")
break
else:
print("Incorrect PIN")marks = [78, 65, 91, 29, 84]
for mark in marks:
if mark < 33:
print("Failed in a subject")
breakstudents = ["Aarav", "Absent", "Riya", "Kabir", "Absent", "Sara"]
for student in students:
if student == "Absent":
continue
print(student)products = ["Laptop", "Out of Stock", "Mouse", "Keyboard", "Out of Stock"]
for product in products:
if product == "Out of Stock":
continue
print("Adding", product, "to cart")continue.for roll in range(1, 21):
if roll % 2 == 0:
continue
print(roll)subjects = ["Maths", "English", "AI", "Science"]
for subject in subjects:
if subject == "AI":
pass
print(subject)products = ["Mouse", "Laptop", "Keyboard"]
for product in products:
if product == "Laptop":
pass
else:
print("Regular product:", product)attendance = ["Present", "Leave", "Present", "Present"]
for status in attendance:
if status == "Present":
print("Attendance marked")
elif status == "Leave":
passdef greet(name="Student"):
print("Hello,", name)
greet("Aarav")
greet()cube = lambda n: n ** 3
print(cube(4))Output: 64.
break different from continue and pass?break stops the loop completely. continue skips the current iteration and moves to the next iteration. pass does nothing; it is used as a placeholder where Python requires a statement.
and, or, and in in a program?and joins conditions that must both be true; or joins alternatives where at least one can be true; in checks whether an item exists inside a sequence such as a list or string.