Conditional Statement & Loops
Theory Questions
What is a conditional statement in Python, and how does it control the flow of a program
What is the purpose of the “else” clause in an “if” statement? Give an example
What is short-circuit evaluation in the context of Python’s conditional statements? How can it be beneficial?
Describe the purpose and usage of the “assert” statement in Python’s conditional testing.
Explain the concept of a ternary operator in Python. When is it useful? Provide an example.
What is the purpose of loops in programming, and how do they contribute to code efficiency and readability
Describe the key differences between a “for” loop and a “while” loop in Python.
How does a “while” loop work, and what is required to prevent it from becoming an infinite loop? Give an example.
Explain the concept of an “iterator” in Python and its significance in “for” loops.
How does the “enumerate()” function enhance the functionality of a “for” loop? Give a use case.
Conditional Statement & Loop PPT
Programming Questions
Write a program that takes an integer input from the user and determines whether it’s even or odd.
Create a program that checks if a given year is a leap year or not.
Design a program that takes a student’s numerical grade as input and converts it to a letter grade using the following scale: A (90-100), B (80-89), C (70-79), D (60-69), F (0-59).
Create a number guessing game where the program generates a random number between 1 and 100, and the user has to guess it. Provide hints such as “too high” or “too low.
Create a program that checks if a given word or phrase is a palindrome (reads the same forwards and backwards).
Write a program to print numbers from 1 to 10 using a “for” loop.
Write a program that calculates the factorial of a given positive integer using a “while” loop
Write a program to print a pattern of stars in the shape of a right triangle using nested loops.
Write a program to print all prime numbers between 1 and 100 using a “for” loop.
Implement a program to generate the Fibonacci series up to a specified number of terms using a “while” loop
Output Questions
x = 15
if x > 10:
print(“x is greater than 10”)
else:
print(“x is not greater than 10”)
num = 7
if num % 2 == 0:
print(“The number is even.”)
else:
print(“The number is odd.”)
temperature = 28
if temperature > 30:
print(“It’s hot outside.”)
elif temperature > 20:
print(“It’s warm outside.”)
else:
print(“It’s cool outside.”)
password = “secretpassword”
if len(password) >= 8:
print(“Password is strong.”)
else:
print(“Password is weak.”)
number = -5
if number > 0:
print(“The number is positive.”)
elif number < 0:
print(“The number is negative.”)
else:
print(“The number is zero.”)
sum = 0
for num in range(1, 6):
sum += num
print(sum)
n = 4
for i in range(n):
print(” ” * (n – i – 1) + “*” * (2 * i + 1))
total = 0
for i in range(1, 11):
if i % 2 == 0:
total += i
print(total)
word = “programming”
for index, char in enumerate(word):
print(f”Character ‘{char}’ is at index {index}”)
for i in range(3):
for j in range(2):
print(i, j, end=” | “)
print()