500 Python Practice Questions and Answers (Easy to Complex)
Q1: Check if a number is positive, negative, or zero (Example 1)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q2: Check if a number is even or odd (Example 2)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q3: Check if a string is empty (Example 3)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q4: Simulate an AND gate with 2 inputs (Example 4)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q5: Print numbers from 1 to 5 using a for loop (Example 5)
Answer:
for i in range(1, 6):
print(i)
Q6: Nested if: Age and License check (Example 6)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q7: Check if a number is in range 10-20 or 30-40 (Example 7)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q8: Factorial using while loop (Example 8)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q9: Simulate a NOT gate (Example 9)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q10: Sum all numbers until user enters 0 (Example 10)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q11: Check if a number is a prime number (advanced) (Example 11)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q12: Find the largest of four numbers (nested if) (Example 12)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q13: Nested loops to create a multiplication table (1 to 5) (Example 13)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q14: Check if a string is a palindrome ignoring cases and spaces (Example 14)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q15: Simulate an XOR gate using if-else (Example 15)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q16: FizzBuzz problem from 1 to 50 (Example 16)
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)
Q17: Check if a number is positive, negative, or zero (Example 17)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q18: Check if a number is even or odd (Example 18)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q19: Check if a string is empty (Example 19)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q20: Simulate an AND gate with 2 inputs (Example 20)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q21: Print numbers from 1 to 5 using a for loop (Example 21)
Answer:
for i in range(1, 6):
print(i)
Q22: Nested if: Age and License check (Example 22)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q23: Check if a number is in range 10-20 or 30-40 (Example 23)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q24: Factorial using while loop (Example 24)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q25: Simulate a NOT gate (Example 25)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q26: Sum all numbers until user enters 0 (Example 26)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q27: Check if a number is a prime number (advanced) (Example 27)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q28: Find the largest of four numbers (nested if) (Example 28)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q29: Nested loops to create a multiplication table (1 to 5) (Example 29)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q30: Check if a string is a palindrome ignoring cases and spaces (Example 30)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q31: Simulate an XOR gate using if-else (Example 31)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q32: FizzBuzz problem from 1 to 50 (Example 32)
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)
Q33: Check if a number is positive, negative, or zero (Example 33)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q34: Check if a number is even or odd (Example 34)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q35: Check if a string is empty (Example 35)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q36: Simulate an AND gate with 2 inputs (Example 36)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q37: Print numbers from 1 to 5 using a for loop (Example 37)
Answer:
for i in range(1, 6):
print(i)
Q38: Nested if: Age and License check (Example 38)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q39: Check if a number is in range 10-20 or 30-40 (Example 39)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q40: Factorial using while loop (Example 40)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q41: Simulate a NOT gate (Example 41)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q42: Sum all numbers until user enters 0 (Example 42)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q43: Check if a number is a prime number (advanced) (Example 43)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q44: Find the largest of four numbers (nested if) (Example 44)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q45: Nested loops to create a multiplication table (1 to 5) (Example 45)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q46: Check if a string is a palindrome ignoring cases and spaces (Example 46)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q47: Simulate an XOR gate using if-else (Example 47)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q48: FizzBuzz problem from 1 to 50 (Example 48)
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)
Q49: Check if a number is positive, negative, or zero (Example 49)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q50: Check if a number is even or odd (Example 50)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q51: Check if a string is empty (Example 51)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q52: Simulate an AND gate with 2 inputs (Example 52)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q53: Print numbers from 1 to 5 using a for loop (Example 53)
Answer:
for i in range(1, 6):
print(i)
Q54: Nested if: Age and License check (Example 54)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q55: Check if a number is in range 10-20 or 30-40 (Example 55)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q56: Factorial using while loop (Example 56)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q57: Simulate a NOT gate (Example 57)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q58: Sum all numbers until user enters 0 (Example 58)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q59: Check if a number is a prime number (advanced) (Example 59)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q60: Find the largest of four numbers (nested if) (Example 60)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q61: Nested loops to create a multiplication table (1 to 5) (Example 61)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q62: Check if a string is a palindrome ignoring cases and spaces (Example 62)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q63: Simulate an XOR gate using if-else (Example 63)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q64: FizzBuzz problem from 1 to 50 (Example 64)
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)
Q65: Check if a number is positive, negative, or zero (Example 65)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q66: Check if a number is even or odd (Example 66)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q67: Check if a string is empty (Example 67)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q68: Simulate an AND gate with 2 inputs (Example 68)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q69: Print numbers from 1 to 5 using a for loop (Example 69)
Answer:
for i in range(1, 6):
print(i)
Q70: Nested if: Age and License check (Example 70)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q71: Check if a number is in range 10-20 or 30-40 (Example 71)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q72: Factorial using while loop (Example 72)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q73: Simulate a NOT gate (Example 73)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q74: Sum all numbers until user enters 0 (Example 74)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q75: Check if a number is a prime number (advanced) (Example 75)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q76: Find the largest of four numbers (nested if) (Example 76)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q77: Nested loops to create a multiplication table (1 to 5) (Example 77)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q78: Check if a string is a palindrome ignoring cases and spaces (Example 78)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q79: Simulate an XOR gate using if-else (Example 79)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q80: FizzBuzz problem from 1 to 50 (Example 80)
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)
Q81: Check if a number is positive, negative, or zero (Example 81)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q82: Check if a number is even or odd (Example 82)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q83: Check if a string is empty (Example 83)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q84: Simulate an AND gate with 2 inputs (Example 84)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q85: Print numbers from 1 to 5 using a for loop (Example 85)
Answer:
for i in range(1, 6):
print(i)
Q86: Nested if: Age and License check (Example 86)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q87: Check if a number is in range 10-20 or 30-40 (Example 87)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q88: Factorial using while loop (Example 88)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q89: Simulate a NOT gate (Example 89)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q90: Sum all numbers until user enters 0 (Example 90)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q91: Check if a number is a prime number (advanced) (Example 91)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q92: Find the largest of four numbers (nested if) (Example 92)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q93: Nested loops to create a multiplication table (1 to 5) (Example 93)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q94: Check if a string is a palindrome ignoring cases and spaces (Example 94)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q95: Simulate an XOR gate using if-else (Example 95)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q96: FizzBuzz problem from 1 to 50 (Example 96)
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)
Q97: Check if a number is positive, negative, or zero (Example 97)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q98: Check if a number is even or odd (Example 98)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q99: Check if a string is empty (Example 99)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q100: Simulate an AND gate with 2 inputs (Example 100)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q101: Print numbers from 1 to 5 using a for loop (Example 101)
Answer:
for i in range(1, 6):
print(i)
Q102: Nested if: Age and License check (Example 102)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q103: Check if a number is in range 10-20 or 30-40 (Example 103)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q104: Factorial using while loop (Example 104)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q105: Simulate a NOT gate (Example 105)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q106: Sum all numbers until user enters 0 (Example 106)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q107: Check if a number is a prime number (advanced) (Example 107)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q108: Find the largest of four numbers (nested if) (Example 108)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q109: Nested loops to create a multiplication table (1 to 5) (Example 109)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q110: Check if a string is a palindrome ignoring cases and spaces (Example 110)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q111: Simulate an XOR gate using if-else (Example 111)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q112: FizzBuzz problem from 1 to 50 (Example 112)
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)
Q113: Check if a number is positive, negative, or zero (Example 113)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q114: Check if a number is even or odd (Example 114)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q115: Check if a string is empty (Example 115)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q116: Simulate an AND gate with 2 inputs (Example 116)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q117: Print numbers from 1 to 5 using a for loop (Example 117)
Answer:
for i in range(1, 6):
print(i)
Q118: Nested if: Age and License check (Example 118)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q119: Check if a number is in range 10-20 or 30-40 (Example 119)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q120: Factorial using while loop (Example 120)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q121: Simulate a NOT gate (Example 121)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q122: Sum all numbers until user enters 0 (Example 122)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q123: Check if a number is a prime number (advanced) (Example 123)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q124: Find the largest of four numbers (nested if) (Example 124)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q125: Nested loops to create a multiplication table (1 to 5) (Example 125)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q126: Check if a string is a palindrome ignoring cases and spaces (Example 126)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q127: Simulate an XOR gate using if-else (Example 127)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q128: FizzBuzz problem from 1 to 50 (Example 128)
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)
Q129: Check if a number is positive, negative, or zero (Example 129)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q130: Check if a number is even or odd (Example 130)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q131: Check if a string is empty (Example 131)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q132: Simulate an AND gate with 2 inputs (Example 132)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q133: Print numbers from 1 to 5 using a for loop (Example 133)
Answer:
for i in range(1, 6):
print(i)
Q134: Nested if: Age and License check (Example 134)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q135: Check if a number is in range 10-20 or 30-40 (Example 135)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q136: Factorial using while loop (Example 136)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q137: Simulate a NOT gate (Example 137)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q138: Sum all numbers until user enters 0 (Example 138)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q139: Check if a number is a prime number (advanced) (Example 139)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q140: Find the largest of four numbers (nested if) (Example 140)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q141: Nested loops to create a multiplication table (1 to 5) (Example 141)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q142: Check if a string is a palindrome ignoring cases and spaces (Example 142)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q143: Simulate an XOR gate using if-else (Example 143)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q144: FizzBuzz problem from 1 to 50 (Example 144)
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)
Q145: Check if a number is positive, negative, or zero (Example 145)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q146: Check if a number is even or odd (Example 146)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q147: Check if a string is empty (Example 147)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q148: Simulate an AND gate with 2 inputs (Example 148)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q149: Print numbers from 1 to 5 using a for loop (Example 149)
Answer:
for i in range(1, 6):
print(i)
Q150: Nested if: Age and License check (Example 150)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q151: Check if a number is in range 10-20 or 30-40 (Example 151)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q152: Factorial using while loop (Example 152)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q153: Simulate a NOT gate (Example 153)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q154: Sum all numbers until user enters 0 (Example 154)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q155: Check if a number is a prime number (advanced) (Example 155)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q156: Find the largest of four numbers (nested if) (Example 156)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q157: Nested loops to create a multiplication table (1 to 5) (Example 157)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q158: Check if a string is a palindrome ignoring cases and spaces (Example 158)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q159: Simulate an XOR gate using if-else (Example 159)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q160: FizzBuzz problem from 1 to 50 (Example 160)
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)
Q161: Check if a number is positive, negative, or zero (Example 161)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q162: Check if a number is even or odd (Example 162)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q163: Check if a string is empty (Example 163)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q164: Simulate an AND gate with 2 inputs (Example 164)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q165: Print numbers from 1 to 5 using a for loop (Example 165)
Answer:
for i in range(1, 6):
print(i)
Q166: Nested if: Age and License check (Example 166)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q167: Check if a number is in range 10-20 or 30-40 (Example 167)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q168: Factorial using while loop (Example 168)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q169: Simulate a NOT gate (Example 169)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q170: Sum all numbers until user enters 0 (Example 170)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q171: Check if a number is a prime number (advanced) (Example 171)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q172: Find the largest of four numbers (nested if) (Example 172)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q173: Nested loops to create a multiplication table (1 to 5) (Example 173)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q174: Check if a string is a palindrome ignoring cases and spaces (Example 174)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q175: Simulate an XOR gate using if-else (Example 175)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q176: FizzBuzz problem from 1 to 50 (Example 176)
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)
Q177: Check if a number is positive, negative, or zero (Example 177)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q178: Check if a number is even or odd (Example 178)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q179: Check if a string is empty (Example 179)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q180: Simulate an AND gate with 2 inputs (Example 180)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q181: Print numbers from 1 to 5 using a for loop (Example 181)
Answer:
for i in range(1, 6):
print(i)
Q182: Nested if: Age and License check (Example 182)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q183: Check if a number is in range 10-20 or 30-40 (Example 183)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q184: Factorial using while loop (Example 184)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q185: Simulate a NOT gate (Example 185)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q186: Sum all numbers until user enters 0 (Example 186)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q187: Check if a number is a prime number (advanced) (Example 187)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q188: Find the largest of four numbers (nested if) (Example 188)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q189: Nested loops to create a multiplication table (1 to 5) (Example 189)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q190: Check if a string is a palindrome ignoring cases and spaces (Example 190)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q191: Simulate an XOR gate using if-else (Example 191)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q192: FizzBuzz problem from 1 to 50 (Example 192)
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)
Q193: Check if a number is positive, negative, or zero (Example 193)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q194: Check if a number is even or odd (Example 194)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q195: Check if a string is empty (Example 195)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q196: Simulate an AND gate with 2 inputs (Example 196)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q197: Print numbers from 1 to 5 using a for loop (Example 197)
Answer:
for i in range(1, 6):
print(i)
Q198: Nested if: Age and License check (Example 198)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q199: Check if a number is in range 10-20 or 30-40 (Example 199)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q200: Factorial using while loop (Example 200)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q201: Simulate a NOT gate (Example 201)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q202: Sum all numbers until user enters 0 (Example 202)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q203: Check if a number is a prime number (advanced) (Example 203)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q204: Find the largest of four numbers (nested if) (Example 204)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q205: Nested loops to create a multiplication table (1 to 5) (Example 205)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q206: Check if a string is a palindrome ignoring cases and spaces (Example 206)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q207: Simulate an XOR gate using if-else (Example 207)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q208: FizzBuzz problem from 1 to 50 (Example 208)
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)
Q209: Check if a number is positive, negative, or zero (Example 209)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q210: Check if a number is even or odd (Example 210)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q211: Check if a string is empty (Example 211)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q212: Simulate an AND gate with 2 inputs (Example 212)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q213: Print numbers from 1 to 5 using a for loop (Example 213)
Answer:
for i in range(1, 6):
print(i)
Q214: Nested if: Age and License check (Example 214)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q215: Check if a number is in range 10-20 or 30-40 (Example 215)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q216: Factorial using while loop (Example 216)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q217: Simulate a NOT gate (Example 217)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q218: Sum all numbers until user enters 0 (Example 218)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q219: Check if a number is a prime number (advanced) (Example 219)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q220: Find the largest of four numbers (nested if) (Example 220)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q221: Nested loops to create a multiplication table (1 to 5) (Example 221)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q222: Check if a string is a palindrome ignoring cases and spaces (Example 222)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q223: Simulate an XOR gate using if-else (Example 223)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q224: FizzBuzz problem from 1 to 50 (Example 224)
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)
Q225: Check if a number is positive, negative, or zero (Example 225)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q226: Check if a number is even or odd (Example 226)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q227: Check if a string is empty (Example 227)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q228: Simulate an AND gate with 2 inputs (Example 228)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q229: Print numbers from 1 to 5 using a for loop (Example 229)
Answer:
for i in range(1, 6):
print(i)
Q230: Nested if: Age and License check (Example 230)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q231: Check if a number is in range 10-20 or 30-40 (Example 231)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q232: Factorial using while loop (Example 232)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q233: Simulate a NOT gate (Example 233)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q234: Sum all numbers until user enters 0 (Example 234)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q235: Check if a number is a prime number (advanced) (Example 235)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q236: Find the largest of four numbers (nested if) (Example 236)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q237: Nested loops to create a multiplication table (1 to 5) (Example 237)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q238: Check if a string is a palindrome ignoring cases and spaces (Example 238)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q239: Simulate an XOR gate using if-else (Example 239)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q240: FizzBuzz problem from 1 to 50 (Example 240)
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)
Q241: Check if a number is positive, negative, or zero (Example 241)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q242: Check if a number is even or odd (Example 242)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q243: Check if a string is empty (Example 243)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q244: Simulate an AND gate with 2 inputs (Example 244)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q245: Print numbers from 1 to 5 using a for loop (Example 245)
Answer:
for i in range(1, 6):
print(i)
Q246: Nested if: Age and License check (Example 246)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q247: Check if a number is in range 10-20 or 30-40 (Example 247)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q248: Factorial using while loop (Example 248)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q249: Simulate a NOT gate (Example 249)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q250: Sum all numbers until user enters 0 (Example 250)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q251: Check if a number is a prime number (advanced) (Example 251)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q252: Find the largest of four numbers (nested if) (Example 252)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q253: Nested loops to create a multiplication table (1 to 5) (Example 253)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q254: Check if a string is a palindrome ignoring cases and spaces (Example 254)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q255: Simulate an XOR gate using if-else (Example 255)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q256: FizzBuzz problem from 1 to 50 (Example 256)
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)
Q257: Check if a number is positive, negative, or zero (Example 257)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q258: Check if a number is even or odd (Example 258)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q259: Check if a string is empty (Example 259)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q260: Simulate an AND gate with 2 inputs (Example 260)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q261: Print numbers from 1 to 5 using a for loop (Example 261)
Answer:
for i in range(1, 6):
print(i)
Q262: Nested if: Age and License check (Example 262)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q263: Check if a number is in range 10-20 or 30-40 (Example 263)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q264: Factorial using while loop (Example 264)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q265: Simulate a NOT gate (Example 265)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q266: Sum all numbers until user enters 0 (Example 266)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q267: Check if a number is a prime number (advanced) (Example 267)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q268: Find the largest of four numbers (nested if) (Example 268)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q269: Nested loops to create a multiplication table (1 to 5) (Example 269)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q270: Check if a string is a palindrome ignoring cases and spaces (Example 270)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q271: Simulate an XOR gate using if-else (Example 271)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q272: FizzBuzz problem from 1 to 50 (Example 272)
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)
Q273: Check if a number is positive, negative, or zero (Example 273)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q274: Check if a number is even or odd (Example 274)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q275: Check if a string is empty (Example 275)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q276: Simulate an AND gate with 2 inputs (Example 276)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q277: Print numbers from 1 to 5 using a for loop (Example 277)
Answer:
for i in range(1, 6):
print(i)
Q278: Nested if: Age and License check (Example 278)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q279: Check if a number is in range 10-20 or 30-40 (Example 279)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q280: Factorial using while loop (Example 280)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q281: Simulate a NOT gate (Example 281)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q282: Sum all numbers until user enters 0 (Example 282)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q283: Check if a number is a prime number (advanced) (Example 283)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q284: Find the largest of four numbers (nested if) (Example 284)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q285: Nested loops to create a multiplication table (1 to 5) (Example 285)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q286: Check if a string is a palindrome ignoring cases and spaces (Example 286)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q287: Simulate an XOR gate using if-else (Example 287)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q288: FizzBuzz problem from 1 to 50 (Example 288)
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)
Q289: Check if a number is positive, negative, or zero (Example 289)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q290: Check if a number is even or odd (Example 290)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q291: Check if a string is empty (Example 291)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q292: Simulate an AND gate with 2 inputs (Example 292)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q293: Print numbers from 1 to 5 using a for loop (Example 293)
Answer:
for i in range(1, 6):
print(i)
Q294: Nested if: Age and License check (Example 294)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q295: Check if a number is in range 10-20 or 30-40 (Example 295)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q296: Factorial using while loop (Example 296)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q297: Simulate a NOT gate (Example 297)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q298: Sum all numbers until user enters 0 (Example 298)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q299: Check if a number is a prime number (advanced) (Example 299)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q300: Find the largest of four numbers (nested if) (Example 300)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q301: Nested loops to create a multiplication table (1 to 5) (Example 301)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q302: Check if a string is a palindrome ignoring cases and spaces (Example 302)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q303: Simulate an XOR gate using if-else (Example 303)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q304: FizzBuzz problem from 1 to 50 (Example 304)
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)
Q305: Check if a number is positive, negative, or zero (Example 305)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q306: Check if a number is even or odd (Example 306)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q307: Check if a string is empty (Example 307)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q308: Simulate an AND gate with 2 inputs (Example 308)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q309: Print numbers from 1 to 5 using a for loop (Example 309)
Answer:
for i in range(1, 6):
print(i)
Q310: Nested if: Age and License check (Example 310)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q311: Check if a number is in range 10-20 or 30-40 (Example 311)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q312: Factorial using while loop (Example 312)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q313: Simulate a NOT gate (Example 313)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q314: Sum all numbers until user enters 0 (Example 314)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q315: Check if a number is a prime number (advanced) (Example 315)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q316: Find the largest of four numbers (nested if) (Example 316)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q317: Nested loops to create a multiplication table (1 to 5) (Example 317)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q318: Check if a string is a palindrome ignoring cases and spaces (Example 318)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q319: Simulate an XOR gate using if-else (Example 319)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q320: FizzBuzz problem from 1 to 50 (Example 320)
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)
Q321: Check if a number is positive, negative, or zero (Example 321)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q322: Check if a number is even or odd (Example 322)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q323: Check if a string is empty (Example 323)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q324: Simulate an AND gate with 2 inputs (Example 324)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q325: Print numbers from 1 to 5 using a for loop (Example 325)
Answer:
for i in range(1, 6):
print(i)
Q326: Nested if: Age and License check (Example 326)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q327: Check if a number is in range 10-20 or 30-40 (Example 327)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q328: Factorial using while loop (Example 328)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q329: Simulate a NOT gate (Example 329)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q330: Sum all numbers until user enters 0 (Example 330)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q331: Check if a number is a prime number (advanced) (Example 331)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q332: Find the largest of four numbers (nested if) (Example 332)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q333: Nested loops to create a multiplication table (1 to 5) (Example 333)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q334: Check if a string is a palindrome ignoring cases and spaces (Example 334)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q335: Simulate an XOR gate using if-else (Example 335)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q336: FizzBuzz problem from 1 to 50 (Example 336)
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)
Q337: Check if a number is positive, negative, or zero (Example 337)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q338: Check if a number is even or odd (Example 338)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q339: Check if a string is empty (Example 339)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q340: Simulate an AND gate with 2 inputs (Example 340)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q341: Print numbers from 1 to 5 using a for loop (Example 341)
Answer:
for i in range(1, 6):
print(i)
Q342: Nested if: Age and License check (Example 342)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q343: Check if a number is in range 10-20 or 30-40 (Example 343)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q344: Factorial using while loop (Example 344)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q345: Simulate a NOT gate (Example 345)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q346: Sum all numbers until user enters 0 (Example 346)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q347: Check if a number is a prime number (advanced) (Example 347)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q348: Find the largest of four numbers (nested if) (Example 348)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q349: Nested loops to create a multiplication table (1 to 5) (Example 349)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q350: Check if a string is a palindrome ignoring cases and spaces (Example 350)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q351: Simulate an XOR gate using if-else (Example 351)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q352: FizzBuzz problem from 1 to 50 (Example 352)
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)
Q353: Check if a number is positive, negative, or zero (Example 353)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q354: Check if a number is even or odd (Example 354)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q355: Check if a string is empty (Example 355)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q356: Simulate an AND gate with 2 inputs (Example 356)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q357: Print numbers from 1 to 5 using a for loop (Example 357)
Answer:
for i in range(1, 6):
print(i)
Q358: Nested if: Age and License check (Example 358)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q359: Check if a number is in range 10-20 or 30-40 (Example 359)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q360: Factorial using while loop (Example 360)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q361: Simulate a NOT gate (Example 361)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q362: Sum all numbers until user enters 0 (Example 362)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q363: Check if a number is a prime number (advanced) (Example 363)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q364: Find the largest of four numbers (nested if) (Example 364)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q365: Nested loops to create a multiplication table (1 to 5) (Example 365)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q366: Check if a string is a palindrome ignoring cases and spaces (Example 366)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q367: Simulate an XOR gate using if-else (Example 367)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q368: FizzBuzz problem from 1 to 50 (Example 368)
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)
Q369: Check if a number is positive, negative, or zero (Example 369)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q370: Check if a number is even or odd (Example 370)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q371: Check if a string is empty (Example 371)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q372: Simulate an AND gate with 2 inputs (Example 372)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q373: Print numbers from 1 to 5 using a for loop (Example 373)
Answer:
for i in range(1, 6):
print(i)
Q374: Nested if: Age and License check (Example 374)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q375: Check if a number is in range 10-20 or 30-40 (Example 375)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q376: Factorial using while loop (Example 376)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q377: Simulate a NOT gate (Example 377)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q378: Sum all numbers until user enters 0 (Example 378)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q379: Check if a number is a prime number (advanced) (Example 379)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q380: Find the largest of four numbers (nested if) (Example 380)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q381: Nested loops to create a multiplication table (1 to 5) (Example 381)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q382: Check if a string is a palindrome ignoring cases and spaces (Example 382)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q383: Simulate an XOR gate using if-else (Example 383)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q384: FizzBuzz problem from 1 to 50 (Example 384)
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)
Q385: Check if a number is positive, negative, or zero (Example 385)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q386: Check if a number is even or odd (Example 386)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q387: Check if a string is empty (Example 387)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q388: Simulate an AND gate with 2 inputs (Example 388)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q389: Print numbers from 1 to 5 using a for loop (Example 389)
Answer:
for i in range(1, 6):
print(i)
Q390: Nested if: Age and License check (Example 390)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q391: Check if a number is in range 10-20 or 30-40 (Example 391)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q392: Factorial using while loop (Example 392)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q393: Simulate a NOT gate (Example 393)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q394: Sum all numbers until user enters 0 (Example 394)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q395: Check if a number is a prime number (advanced) (Example 395)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q396: Find the largest of four numbers (nested if) (Example 396)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q397: Nested loops to create a multiplication table (1 to 5) (Example 397)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q398: Check if a string is a palindrome ignoring cases and spaces (Example 398)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q399: Simulate an XOR gate using if-else (Example 399)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q400: FizzBuzz problem from 1 to 50 (Example 400)
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)
Q401: Check if a number is positive, negative, or zero (Example 401)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q402: Check if a number is even or odd (Example 402)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q403: Check if a string is empty (Example 403)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q404: Simulate an AND gate with 2 inputs (Example 404)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q405: Print numbers from 1 to 5 using a for loop (Example 405)
Answer:
for i in range(1, 6):
print(i)
Q406: Nested if: Age and License check (Example 406)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q407: Check if a number is in range 10-20 or 30-40 (Example 407)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q408: Factorial using while loop (Example 408)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q409: Simulate a NOT gate (Example 409)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q410: Sum all numbers until user enters 0 (Example 410)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q411: Check if a number is a prime number (advanced) (Example 411)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q412: Find the largest of four numbers (nested if) (Example 412)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q413: Nested loops to create a multiplication table (1 to 5) (Example 413)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q414: Check if a string is a palindrome ignoring cases and spaces (Example 414)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q415: Simulate an XOR gate using if-else (Example 415)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q416: FizzBuzz problem from 1 to 50 (Example 416)
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)
Q417: Check if a number is positive, negative, or zero (Example 417)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q418: Check if a number is even or odd (Example 418)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q419: Check if a string is empty (Example 419)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q420: Simulate an AND gate with 2 inputs (Example 420)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q421: Print numbers from 1 to 5 using a for loop (Example 421)
Answer:
for i in range(1, 6):
print(i)
Q422: Nested if: Age and License check (Example 422)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q423: Check if a number is in range 10-20 or 30-40 (Example 423)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q424: Factorial using while loop (Example 424)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q425: Simulate a NOT gate (Example 425)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q426: Sum all numbers until user enters 0 (Example 426)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q427: Check if a number is a prime number (advanced) (Example 427)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q428: Find the largest of four numbers (nested if) (Example 428)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q429: Nested loops to create a multiplication table (1 to 5) (Example 429)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q430: Check if a string is a palindrome ignoring cases and spaces (Example 430)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q431: Simulate an XOR gate using if-else (Example 431)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q432: FizzBuzz problem from 1 to 50 (Example 432)
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)
Q433: Check if a number is positive, negative, or zero (Example 433)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q434: Check if a number is even or odd (Example 434)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q435: Check if a string is empty (Example 435)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q436: Simulate an AND gate with 2 inputs (Example 436)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q437: Print numbers from 1 to 5 using a for loop (Example 437)
Answer:
for i in range(1, 6):
print(i)
Q438: Nested if: Age and License check (Example 438)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q439: Check if a number is in range 10-20 or 30-40 (Example 439)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q440: Factorial using while loop (Example 440)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q441: Simulate a NOT gate (Example 441)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q442: Sum all numbers until user enters 0 (Example 442)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q443: Check if a number is a prime number (advanced) (Example 443)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q444: Find the largest of four numbers (nested if) (Example 444)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q445: Nested loops to create a multiplication table (1 to 5) (Example 445)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q446: Check if a string is a palindrome ignoring cases and spaces (Example 446)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q447: Simulate an XOR gate using if-else (Example 447)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q448: FizzBuzz problem from 1 to 50 (Example 448)
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)
Q449: Check if a number is positive, negative, or zero (Example 449)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q450: Check if a number is even or odd (Example 450)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q451: Check if a string is empty (Example 451)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q452: Simulate an AND gate with 2 inputs (Example 452)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q453: Print numbers from 1 to 5 using a for loop (Example 453)
Answer:
for i in range(1, 6):
print(i)
Q454: Nested if: Age and License check (Example 454)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q455: Check if a number is in range 10-20 or 30-40 (Example 455)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q456: Factorial using while loop (Example 456)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q457: Simulate a NOT gate (Example 457)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q458: Sum all numbers until user enters 0 (Example 458)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q459: Check if a number is a prime number (advanced) (Example 459)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q460: Find the largest of four numbers (nested if) (Example 460)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q461: Nested loops to create a multiplication table (1 to 5) (Example 461)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q462: Check if a string is a palindrome ignoring cases and spaces (Example 462)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q463: Simulate an XOR gate using if-else (Example 463)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q464: FizzBuzz problem from 1 to 50 (Example 464)
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)
Q465: Check if a number is positive, negative, or zero (Example 465)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q466: Check if a number is even or odd (Example 466)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q467: Check if a string is empty (Example 467)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q468: Simulate an AND gate with 2 inputs (Example 468)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q469: Print numbers from 1 to 5 using a for loop (Example 469)
Answer:
for i in range(1, 6):
print(i)
Q470: Nested if: Age and License check (Example 470)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q471: Check if a number is in range 10-20 or 30-40 (Example 471)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q472: Factorial using while loop (Example 472)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q473: Simulate a NOT gate (Example 473)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q474: Sum all numbers until user enters 0 (Example 474)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q475: Check if a number is a prime number (advanced) (Example 475)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q476: Find the largest of four numbers (nested if) (Example 476)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q477: Nested loops to create a multiplication table (1 to 5) (Example 477)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q478: Check if a string is a palindrome ignoring cases and spaces (Example 478)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q479: Simulate an XOR gate using if-else (Example 479)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q480: FizzBuzz problem from 1 to 50 (Example 480)
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)
Q481: Check if a number is positive, negative, or zero (Example 481)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q482: Check if a number is even or odd (Example 482)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q483: Check if a string is empty (Example 483)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q484: Simulate an AND gate with 2 inputs (Example 484)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")
Q485: Print numbers from 1 to 5 using a for loop (Example 485)
Answer:
for i in range(1, 6):
print(i)
Q486: Nested if: Age and License check (Example 486)
Answer:
age = int(input("Enter your age: "))
if age >= 18:
has_license = input("Do you have a license? (yes/no): ")
if has_license.lower() == "yes":
print("You can drive")
else:
print("You need a license to drive")
else:
print("Too young to drive")
Q487: Check if a number is in range 10-20 or 30-40 (Example 487)
Answer:
num = int(input("Enter a number: "))
if (10 <= num <= 20) or (30 <= num <= 40):
print("Number is in range")
else:
print("Number is not in range")
Q488: Factorial using while loop (Example 488)
Answer:
num = int(input("Enter a number: "))
factorial = 1
i=1
while i <= num:
factorial *= i
i += 1
print("Factorial:", factorial)
Q489: Simulate a NOT gate (Example 489)
Answer:
a = int(input("Enter 0 or 1: "))
if a == 0:
print("NOT gate output: 1")
elif a == 1:
print("NOT gate output: 0")
else:
print("Invalid input")
Q490: Sum all numbers until user enters 0 (Example 490)
Answer:
total = 0
while True:
num = float(input("Enter number (0 to stop): "))
if num == 0:
break
total += num
print("Total sum is:", total)
Q491: Check if a number is a prime number (advanced) (Example 491)
Answer:
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print("Not a prime number")
break
else:
print("Prime number")
else:
print("Not a prime number")
Q492: Find the largest of four numbers (nested if) (Example 492)
Answer:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))
if a > b:
if a > c:
if a > d:
largest = a
else:
largest = d
elif c > d:
largest = c
else:
largest = d
else:
if b > c:
if b > d:
largest = b
else:
largest = d
elif c > d:
largest = c
else:
largest = d
print("Largest number is:", largest)
Q493: Nested loops to create a multiplication table (1 to 5) (Example 493)
Answer:
for i in range(1, 6):
for j in range(1, 6):
print(f"{i} x {j} = {i * j}")
print("-----")
Q494: Check if a string is a palindrome ignoring cases and spaces (Example 494)
Answer:
text = input("Enter a string: ").replace(" ", "").lower()
if text == text[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Q495: Simulate an XOR gate using if-else (Example 495)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if (a == 1 and b == 0) or (a == 0 and b == 1):
print("XOR gate output: 1")
else:
print("XOR gate output: 0")
Q496: FizzBuzz problem from 1 to 50 (Example 496)
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)
Q497: Check if a number is positive, negative, or zero (Example 497)
Answer:
num = float(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
Q498: Check if a number is even or odd (Example 498)
Answer:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q499: Check if a string is empty (Example 499)
Answer:
text = input("Enter some text: ")
if text:
print("String is not empty")
else:
print("String is empty")
Q500: Simulate an AND gate with 2 inputs (Example 500)
Answer:
a = int(input("Enter first input (0 or 1): "))
b = int(input("Enter second input (0 or 1): "))
if a == 1 and b == 1:
print("AND gate output: 1")
else:
print("AND gate output: 0")