0% found this document useful (0 votes)
2 views8 pages

Python Practice Questions - SS26

The document contains a series of Python practice questions and their corresponding answers, covering basic programming concepts such as checking even or odd numbers, finding larger numbers, and calculating factorials. It also includes practice questions without answers, focusing on topics like calculating electricity bills and summing odd numbers. Each question is designed to help learners improve their Python coding skills through practical examples.

Uploaded by

AYUSHMAN
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)
2 views8 pages

Python Practice Questions - SS26

The document contains a series of Python practice questions and their corresponding answers, covering basic programming concepts such as checking even or odd numbers, finding larger numbers, and calculating factorials. It also includes practice questions without answers, focusing on topics like calculating electricity bills and summing odd numbers. Each question is designed to help learners improve their Python coding skills through practical examples.

Uploaded by

AYUSHMAN
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

Python Practice Questions

1. Check Even or Odd


Question: Take a number as input and print whether it is even or odd.

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

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

2. Find the Larger Number


Question: Take two numbers and print the greater number.

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

if a > b:
print(a)
else:
print(b)

3. Check Positive, Negative, or Zero


Question: Determine whether a number 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")

4. Print Numbers from 1 to 10


Question: Use a loop to print numbers from 1 to 10.

Answer
for i in range(1, 11):
print(i)

5. Sum of First N Numbers


Question: Take N as input and calculate the sum of first N natural numbers.

Answer
n = int(input("Enter N: "))
total = 0

for i in range(1, n + 1):


total += i

print("Sum =", total)

6. Multiplication Table
Question: Print the multiplication table of a given number.

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

for i in range(1, 11):


print(num, "x", i, "=", num * i)
7. Count from 10 to 1
Question: Print numbers from 10 to 1 using a loop.

Answer
for i in range(10, 0, -1):
print(i)

8. Calculate Factorial
Question: Find the factorial of a number.

Answer
n = int(input("Enter a number: "))
fact = 1

for i in range(1, n + 1):


fact *= i

print("Factorial =", fact)

9. Count Digits in a Number


Question: Count the number of digits in an integer.

Answer
num = int(input("Enter a number: "))
count = 0

while num > 0:


count += 1
num //= 10

print("Digits =", count)


10. Reverse a Number
Question: Reverse the digits of a number.

Answer
num = int(input("Enter a number: "))
reverse = 0

while num > 0:


digit = num % 10
reverse = reverse * 10 + digit
num //= 10

print(reverse)

11. Check Leap Year


Question: Determine whether a year is a leap year.

Answer
year = int(input("Enter year: "))

if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):


print("Leap Year")
else:
print("Not a Leap Year")

12. Sum of Even Numbers from 1 to N


Question: Find the sum of all even numbers between 1 and N.

Answer
n = int(input("Enter N: "))
total = 0

for i in range(2, n + 1, 2):


total += i
print(total)

13. Simple Calculator


Question: Create a calculator using +, -, *, / operators.

Answer
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
op = input("Enter operator: ")

if op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "*":
print(a * b)
elif op == "/":
print(a / b)
else:
print("Invalid operator")

14. Find Greatest Among Three Numbers


Question: Find the largest of three numbers.

Answer
a = int(input())
b = int(input())
c = int(input())

if a >= b and a >= c:


print(a)
elif b >= c:
print(b)
else:
print(c)
15. Prime Number Check
Question: Check whether a number is prime.

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

if num < 2:
print("Not Prime")
else:
prime = True

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


if num % i == 0:
prime = False
break

if prime:
print("Prime")
else:
print("Not Prime")

16. Armstrong Number Check


Question: Check whether a number is an Armstrong number.

Example: 153 = 1³ + 5³ + 3³

Answer
num = int(input("Enter number: "))
temp = num
digits = len(str(num))
total = 0

while temp > 0:


digit = temp % 10
total += digit ** digits
temp //= 10

if total == num:
print("Armstrong Number")
else:
print("Not Armstrong Number")

17. Pattern Printing


Question: Print the following pattern for N = 5

*
**
***
****
*****

Answer
n=5

for i in range(1, n + 1):


print("*" * i)

18. Number Guessing Game


Question: Generate a secret number and allow the user to guess until correct.

Answer
secret = 7

while True:
guess = int(input("Guess: "))

if guess == secret:
print("Correct!")
break
elif guess < secret:
print("Too Low")
else:
print("Too High")

19. FizzBuzz
Question: Print numbers from 1 to 50:

●​ Multiples of 3 → Fizz
●​ Multiples of 5 → Buzz
●​ Multiples of both → FizzBuzz

Answer
for i in range(1, 51):

if i % 3 == 0 and i % 5 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)

Practice Questions without answers

1) Calculate Electricity Bill

Take the number of units consumed as input and calculate the bill based on:

●​ First 100 units: ₹5 per unit


●​ Next 100 units: ₹7 per unit
●​ Above 200 units: ₹10 per unit

2) Sum of Odd Numbers

Take a number N as input and calculate the sum of all odd numbers from 1 to N.

3) Calculate Power Without Using

Take two numbers as input: base and exponent. Calculate the result of base raised to the
exponent using loops only.

Example:​
Input: 2, 5​
Output: 32

You might also like