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