0% found this document useful (0 votes)
47 views2 pages

Class9 Python Practice Solutions

Uploaded by

deepagrawal492
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)
47 views2 pages

Class9 Python Practice Solutions

Uploaded by

deepagrawal492
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

Class 9 Python Practice Programs - Solutions

Q1. Print first 10 natural numbers


for i in range(1, 11):
print(i)
This prints numbers from 1 to 10 using a for loop.

Q2. Multiplication table of a number


n = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")
Takes a number and prints its multiplication table.

Q3. Squares from 1 to 15


for i in range(1, 16):
print(f"Square of {i} = {i * i}")
Prints square of numbers 1 to 15.

Q4. Even numbers between 1 and 50


for i in range(2, 51, 2):
print(i)
Prints even numbers from 2 to 50.

Q5. Sum of first 20 natural numbers


total = 0
for i in range(1, 21):
total += i
print("Sum =", total)
Calculates sum = 210.

Q6. Numbers 1–10 using while loop


i = 1
while i <= 10:
print(i)
i += 1
Prints 1 to 10 using while loop.

Q7. Reverse of a number


n = int(input("Enter a number: "))
rev = 0
while n > 0:
digit = n % 10
rev = rev * 10 + digit
n //= 10
print("Reversed number =", rev)
Reverses digits of a number.

Q8. Print digits of a number


n = int(input("Enter a number: "))
print("Digits are:")
while n > 0:
digit = n % 10
print(digit)
n //= 10
Prints digits one by one.

Q11. Positive, Negative or Zero


n = int(input("Enter a number: "))
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")
Checks if number is positive, negative or zero.

Q12. Even or Odd


n = int(input("Enter a number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")
Checks if number is even or odd.

Q13. Largest of three numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:


print("Largest =", a)
elif b >= a and b >= c:
print("Largest =", b)
else:
print("Largest =", c)
Finds largest among three numbers.

Q14. Create list using append()


items = []
n = int(input("How many items? "))
for i in range(n):
item = input("Enter item: ")
items.append(item)
print("Final list =", items)
Creates a list with user input.

Q15. Create list of integers and sort


nums = []
n = int(input("How many numbers? "))
for i in range(n):
num = int(input("Enter number: "))
nums.append(num)
nums.sort()
print("Sorted list =", nums)
Creates list of integers and sorts it.

You might also like