Learn  •  Practice  •  Grow

Suhail AtharQuestion Bank

Python practice questions for Classes VI, VII & VIII

60+Questions
</>WithAnswers
Class-wiseOrganisation
Real-lifeExamples
“Small steps in coding today, big possibilities tomorrow.”
— Suhail Athar
🌱

Class VI

Basics & Mathematics

Simple programs to build a strong Python foundation.

22 Questions
📖

Class VII

Logic & Strings

Booleans, if–else decisions and string operations.

8 Questions

Class VIII

Lists, Loops & Modules

Lists, for/while loops, modules and real-life programs.

30 Questions
🎁

Bonus Code

Extra Concepts

break, continue, pass, functions and miscellaneous challenges.

18 Questions

Class VI — Python Foundations

Easy arithmetic, variables, input(), type(), expressions, and simple real-life calculations. No loops or conditional logic are required.

Foundation

Basic Maths & Variables

01Find the area and circumference of a circle after accepting its radius from the user.
Answer
radius = float(input("Enter radius: "))
area = 3.14 * radius * radius
circumference = 2 * 3.14 * radius

print("Area =", area)
print("Circumference =", circumference)
02On a farm there are 12 cows and 18 sheep. How many legs do the animals have in total?
Answer
cows = 12
sheep = 18
total_legs = (cows * 4) + (sheep * 4)
print("Total legs on the farm =", total_legs)

Output: 120

03A train travels at 60 miles per hour. How far will it travel in 4 hours?
Answer
speed = 60
time = 4
distance = speed * time
print("Distance =", distance, "miles")

Output: 240 miles

04Each student needs 7 notebooks. If there are 24 students, how many notebooks are needed?
Answer
students = 24
notebooks_each = 7
total_notebooks = students * notebooks_each
print("Total notebooks =", total_notebooks)

Output: 168

05A marathon is 42 kilometres long. Convert the distance into metres.
Answer
km = 42
metres = km * 1000
print("Total metres =", metres)

Output: 42000 metres

06Jane has 15 apples and gives 3 apples to each friend. How many friends can receive apples?
Answer
apples = 15
apples_each = 3
friends = apples // apples_each
print("Total friends =", friends)

Output: 5 friends

07Rahul sells 2 kg of apples for ₹180 and Roshan sells 4 kg for ₹300. Find the cost per kilogram for both.
Answer
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.

08If 6 cans of juice cost ₹210, what is the cost of 4 cans?
Answer
cost_6 = 210
cost_1 = cost_6 / 6
cost_4 = cost_1 * 4
print("Cost of 4 cans =", cost_4, "INR")

Output: ₹140

09A batsman scored 36, 35, 50 and 55 runs in four innings. Calculate his mean score.
Answer
m1, m2, m3, m4 = 36, 35, 50, 55
mean = (m1 + m2 + m3 + m4) / 4
print("Mean score =", mean)

Output: 44

10Evaluate 3y(2y − 7) − 3(y − 4) − 63 for y = −2 using Python.
Answer
y = -2
value = 3*y*(2*y - 7) - 3*(y - 4) - 63
print(value)

Output: 21

11The area of a rhombus is 240 cm² and one diagonal is 16 cm. Find the other diagonal. Use Area = ½ × d1 × d2.
Answer
d1 = 16
area = 240
d2 = area / (0.5 * d1)
print("Second diagonal =", d2, "cm")

Output: 30 cm

12An open aquarium has length 80 cm, width 30 cm and height 40 cm. Find the area required to cover its four vertical walls.
Answer
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²

13A closed cylindrical tank has radius 7 m and height 3 m. Find the sheet required using TSA = 2πr(r+h).
Answer
r = 7
h = 3
tsa = round(2 * 3.14 * r * (r + h), 0)
print("Sheet needed =", tsa, "sq. metre")

Output: approximately 440 m².

14Evaluate (8⁻¹ × 5³) ÷ 2⁻⁴ using Python.
Answer
print(((8**-1) * (5**3)) / (2**-4))

Output: 250.0

15Find the square root of 19 using the exponent operator.
Answer
print(19 ** 0.5)

Output: approximately 4.3589.

Input, Type & Variables

16Ask the user for their name and age, then calculate the year in which they will turn 100. Ask for the current year too.
Answer
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)
17Write a program that accepts a value from the user and displays the data type returned by input().
Answer
value = input("Enter anything: ")
print(type(value))

input() returns a string unless you convert it.

18Give a real-life situation where variables could be used in a program.
Answer

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.

19Write a Python program using three variables whose final result is 26.7.
Answer
a = 10
b = 8
c = 8.7
result = a + b + c
print(result)

Output: 26.7. Many other correct combinations are possible.

20Why do variable names matter?
Answer

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.

21Think about your daily life. Name something simple or silly that could be measured and stored in a Python variable.
Sample answer

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.

22Why can changing the order of Python commands change a program's result?
Answer

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.

Class VII — Decisions & Strings

Boolean expressions, comparisons, basic if/elif/else, and simple string operations.

Decision Making
01Create a program to determine whether a number entered by the user is positive, negative or zero.
Answer
num = float(input("Enter a number: "))

if num > 0:
    print("Positive")
elif num < 0:
    print("Negative")
else:
    print("Zero")
02Ask the user for a number. Print whether it is even or odd.
Answer
num = int(input("Enter a number: "))

if num % 2 == 0:
    print("The number is even.")
else:
    print("The number is odd.")
03Ask the user for a word. Print whether the number of characters in the word is even or odd.
Answer
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.")
04Create a language greeting program: print “Hello” for EN, “Hola” for ES and “Bonjour” for FR.
Answer
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")
05Write a program that displays “Hello” if a number is a multiple of 5; otherwise display “Bye”.
Answer
num = int(input("Enter a number: "))

if num % 5 == 0:
    print("Hello")
else:
    print("Bye")
06What is a Boolean value in Python? Give one example.
Answer

A Boolean is a value that is either True or False. Comparison expressions produce Boolean results.

print(10 > 5)   # True
print(3 == 7)   # False
07Create a program that asks for a word and prints it in uppercase, lowercase, and reversed form.
Answer
word = input("Enter a word: ")

print("Uppercase:", word.upper())
print("Lowercase:", word.lower())
print("Reversed:", word[::-1])
08Create a simple palindrome checker using string reversal.
Answer
word = input("Enter a word: ")

if word == word[::-1]:
    print("Palindrome")
else:
    print("Not a palindrome")

More If–Else & Real-Life Programs

09Create a program that asks the user for today's weather and displays a suitable suggestion.
Answer
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!")
10Write a program to find the greatest number between two numbers.
Answer
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.")
11Write a program to give free tickets to kids and senior citizens. Assume children below 12 and senior citizens aged 60 or above get a free ticket.
Answer
age = int(input("Enter your age: "))

if age < 12 or age >= 60:
    print("Free ticket!")
else:
    print("Regular ticket required.")
12Find the largest number among three numbers.
Answer
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)
13Write a program to swap two numbers using a temporary variable.
Answer
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)

Menu-Driven If–Elif Programs

14Create a simple bank program to check balance, deposit money, or withdraw money using if–elif–else.
Answer
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")
15Create a student result program that calculates total marks, percentage and grade for five subjects.
Answer
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")
16Create a menu-driven program to calculate the area of a rectangle, circle, triangle or square.
Answer
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")
17Create a program that checks which academic stream a student is eligible for according to their selected stream and percentage.
Answer
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")

Class VIII — Lists, Loops & Logic

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.

Applied Python

List Length & Traversal

01AFind the length of every item in a list using len() and a for loop.
Answer
items = ["Python", "AI", "HTML", "Computer"]

for item in items:
    print(item, "has", len(item), "characters")

Lists & For Loops

01Add the sub-list ["socks", "tshirt", "pajamas"] to the end of gift_list as one nested list item.
Answer
gift_list = ["socks", "4K drone", "wine", "jam"]
gift_list.append(["socks", "tshirt", "pajamas"])
print(gift_list)
02Remove "broccoli" from the list using both .index() and .pop().
Answer
lst = ["milk", "banana", "broccoli"]

position = lst.index("broccoli")
lst.pop(position)

print(lst)
03Use a for loop to print “Hello!” followed by each name in the list.
Answer
names = ["Sam", "Lisa", "Micha", "Dave", "Wyatt", "Emma", "Sage"]

for name in names:
    print("Hello!,", name)
04Count how many characters are in the string "Civilization" by increasing a counter inside a for loop.
Answer
text = "Civilization"
c = 0

for i in text:
    c = c + 1

print(c)

The loop adds 1 a total of 12 times.

05Use a for loop to append the square of each number from lst1 into lst2.
Answer
lst1 = [3, 7, 6, 8, 9, 11, 15, 25]
lst2 = []

for num in lst1:
    lst2.append(num ** 2)

print(lst2)
06Use a for loop with an if statement to create a new list containing only positive numbers.
Answer
lst1 = [111, 32, -9, -45, -17, 9, 85, -10]
lst2 = []

for num in lst1:
    if num > 0:
        lst2.append(num)

print(lst2)
07Print the first 10 natural numbers using a for loop.
Answer
for i in range(1, 11):
    print(i)
08Print the first 10 even numbers using a for loop.
Answer
for i in range(2, 22, 2):
    print(i)
09Print the first 10 odd numbers using a for loop.
Answer
for i in range(1, 21, 2):
    print(i)
10Print the first 10 even numbers in reverse order.
Answer
for i in range(20, 0, -2):
    print(i)
11Accept 10 numbers from the user and display their average.
Answer
total = 0

for i in range(10):
    num = float(input("Enter number: "))
    total = total + num

print("Average =", total / 10)
12Find the factorial of a number using a for loop.
Answer
num = int(input("Enter a number: "))
factorial = 1

for i in range(1, num + 1):
    factorial = factorial * i

print("Factorial =", factorial)

While Loops

13Calculate the factorial of a given number using a while loop.
Answer
num = int(input("Enter a number: "))
factorial = 1
i = 1

while i <= num:
    factorial *= i
    i += 1

print("Factorial =", factorial)
14Generate the Fibonacci sequence for a specified number of terms using a while loop.
Answer
terms = int(input("How many terms? "))
a, b = 0, 1
count = 0

while count < terms:
    print(a)
    a, b = b, a + b
    count += 1
15Find the sum of the digits of a number using a while loop.
Answer
num = int(input("Enter a positive integer: "))
total = 0

while num:
    digit = num % 10
    total += digit
    num //= 10

print("Sum of digits =", total)
16Find the product of the digits of a number using a while loop.
Answer
num = int(input("Enter a positive integer: "))
product = 1

while num:
    digit = num % 10
    product *= digit
    num //= 10

print("Product of digits =", product)
17Take a positive integer as input and print its reverse using a while loop.
Answer
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)
18Print the multiplication table of a given number using a while loop.
Answer
num = int(input("Enter a number: "))
i = 1

while i <= 10:
    print(num, "x", i, "=", num * i)
    i += 1
19Check whether a string is a palindrome using a while loop.
Answer
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")
20Check whether a number is prime using a while loop.
Answer
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")
21Count all non-whitespace characters in a string using a while loop.
Answer
text = input("Enter text: ")
i = 0
count = 0

while i < len(text):
    if text[i] != " ":
        count += 1
    i += 1

print("Characters excluding spaces =", count)
22Generate the Collatz sequence for a positive number using a while loop.
Answer
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)

Random, Time & Compound Logic

23Create a number guessing game. The computer chooses a random number from 1 to 100 and gives “too high” or “too low” hints until the user guesses correctly.
Answer
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!")
24For numbers from 1 to 999, count how many would be labelled Fizz (multiple of 5 only), Buzz (multiple of 3 only), and FizzBuzz (multiple of both 3 and 5).
Answer
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.

25Use the in keyword to check whether a student name is present in a list.
Answer
students = ["Aman", "Sara", "Riya", "Kabir"]
name = input("Enter a name: ")

if name in students:
    print("Student found")
else:
    print("Student not found")
26Use the or keyword to check whether a user entered “yes” or “y”.
Answer
choice = input("Continue? ").lower()

if choice == "yes" or choice == "y":
    print("Continuing...")
else:
    print("Stopped.")
27Use the time module to create a simple 5-second countdown.
Answer
import time

for i in range(5, 0, -1):
    print(i)
    time.sleep(1)

print("Go!")
28Can a for loop become infinite? Where might a for loop be useful in real life?
Answer

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.

Bonus Code

Extra programs for students who are ready to explore beyond the core Class VI–VIII sequence.

Extension

For Loop + break

B01Searching for a Missing Book — search a list for “Python” and stop when the book is found.
Answer
books = ["Maths", "Science", "Python", "English", "AI"]

for book in books:
    if book == "Python":
        print("Python book found!")
        break
B02ATM PIN Attempts — check attempted PINs and stop when the correct PIN “1234” is found.
Answer
attempts = ["1111", "2468", "1234", "9999"]

for pin in attempts:
    if pin == "1234":
        print("Access Granted")
        break
    else:
        print("Incorrect PIN")
B03Finding the First Failed Subject — stop checking as soon as a mark below 33 is found.
Answer
marks = [78, 65, 91, 29, 84]

for mark in marks:
    if mark < 33:
        print("Failed in a subject")
        break

For Loop + continue

B04Skip Absent Students — print only present students from a list containing “Absent”.
Answer
students = ["Aarav", "Absent", "Riya", "Kabir", "Absent", "Sara"]

for student in students:
    if student == "Absent":
        continue
    print(student)
B05Skip Unavailable Products — print “Adding product to cart” only for products that are not “Out of Stock”.
Answer
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")
B06Skip Even Numbers — display only odd roll numbers from 1 to 20 using continue.
Answer
for roll in range(1, 21):
    if roll % 2 == 0:
        continue
    print(roll)

For Loop + pass

B07Future School Subjects — print all subjects, but do nothing when the subject is “AI” because its activity will be added later.
Answer
subjects = ["Maths", "English", "AI", "Science"]

for subject in subjects:
    if subject == "AI":
        pass
    print(subject)
B08Online Shopping — when the product is “Laptop”, leave the block empty for a future special discount feature.
Answer
products = ["Mouse", "Laptop", "Keyboard"]

for product in products:
    if product == "Laptop":
        pass
    else:
        print("Regular product:", product)
B09School Attendance System — print “Attendance marked” for Present; do nothing yet for Leave.
Answer
attendance = ["Present", "Leave", "Present", "Present"]

for status in attendance:
    if status == "Present":
        print("Attendance marked")
    elif status == "Leave":
        pass

Functions

B10Write a function to greet a user. If no name is supplied, use a default name.
Answer
def greet(name="Student"):
    print("Hello,", name)

greet("Aarav")
greet()
B11Create a one-line lambda function to find the cube of a number.
Answer
cube = lambda n: n ** 3

print(cube(4))

Output: 64.

Miscellaneous

B12Why is break different from continue and pass?
Answer

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.

B13When would you use and, or, and in in a program?
Answer

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.

Code with curiosity, practice with purpose, and keep building. — Suhail Athar —