Control Flow Questions
Conditional Statements
Question 1: Simple if Statement
Write a program that asks the user to input a number and prints whether the number is
positive.
Question 2: if-else Statement
Write a program that asks the user to input a number and prints whether the number is
positive or negative.
Question 3: if-elif-else Statement
Write a program that asks the user to input a number and prints whether the number is
positive, negative, or zero.
Question 4: Nested if Statement
Write a program that asks the user to input a number and prints whether the number is
positive and even, positive and odd, or negative.
Loops
Question 5: for Loop
Write a program that prints all the numbers from 1 to 10 using a for loop.
Question 6: while Loop
Write a program that prints all the numbers from 1 to 10 using a while loop.
Question 7: Nested Loops
Write a program that prints a 5x5 grid of asterisks (*) using nested loops.
Question 8: break Statement
Write a program that asks the user to input numbers until they input 0. The program should
print the sum of all the input numbers.
Question 9: continue Statement
Write a program that prints all the numbers from 1 to 10 except 5 using a for loop and
continue statement.
Question 10: pass Statement
Write a program that defines an empty function using the pass statement.
Question 11: Combining Loops and Conditionals
Write a program that asks the user to input a number and prints all the even numbers from 1
to that number using a for loop.
Question 12: Factorial Calculation
Write a program that calculates the factorial of a number input by the user using a while
loop.
Question 13: Sum of Digits
Write a program that calculates the sum of the digits of a number input by the user using a
while loop.
Question 14: Prime Number Check
Write a program that checks if a number input by the user is a prime number using a for
loop.
Question 15: Fibonacci Sequence
Write a program that prints the first n Fibonacci numbers, where n is input by the user.