1. What is the purpose of the if statement in Python?
2. Can an if statement have multiple conditions? How can this be achieved?
3. How does the if-elif-else statement work in Python?
4. What is the difference between elif and else in an if-elif-else construct?
5. Describe how a while loop works in Python.
6. What are some common use cases for a while loop?
7. How does a for loop differ from a while loop in Python?
8. What is the purpose of the range() function when used in a for loop?
9. What is the role of the break statement in loops?
10. Can the break statement be used in both for and while loops?
11. How does the continue statement affect loop execution?
12. How is the continue statement different from the break statement?
13. What is the purpose of the assert statement in Python?
14. What is the function of the pass statement in Python?
Programming Questions:
1. Write a Python program to check if a number is positive, negative, or zero.
2. Write a Python program to determine if a year is a leap year.
3. Write a Python program to calculate the sum of all numbers from 1 to n using a while loop.
4. Write a Python program to find the factorial of a number using a while loop.
5. Write a Python program to iterate over a list and print each element using a for loop.
6. Write a Python program to calculate the sum of all even numbers in a list using a for loop.
7. Write a Python program that reads numbers from a list and stops reading when it encounters a negative number.
8. Write a Python program to find the first prime number in a list of numbers and stop searching after finding it.
9. Write a Python program to skip printing numbers that are multiples of 3 in a range from 1 to 10 using a continue statement.
10. Write a Python program to iterate over a string and print only the vowels, using a continue statement.
11. Write a Python Program that uses assert to check if a given number is non-negative.
12. Write a Python Program that uses assert to verify that a list is not empty.
13. Write a Python program that uses the pass statement in a loop for a feature you plan to implement later.
Pattern Programs
1. Write a Python program to print the following right-angled triangle pattern of stars
*
**
***
****
*****
2. Write a Python program to print the following inverted right-angled triangle pattern of stars:
*****
****
***
**
*
3. Write a Python program to print the following pyramid pattern of stars:
*
***
*****
*******
*********
4. Write a Python program to print the following diamond pattern of stars:
*
***
*****
***
*
5. Write a Python program to print the following number pyramid pattern:
1
121
12321
1234321
123454321
6. Write a Python program to print the following hollow square pattern:
*****
* *
* *
* *
*****
7. Write a Python program to print Floyd’s triangle:
1
2 3
4 5 6
7 8 9 10
8. Write a Python program to print Pascal’s triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
9. Write a Python program to print the following right-angled triangle pattern with numbers:
1
12
123
1234
10. Write a Python program to print a square pattern of numbers, where each row contains the same number:
11111
22222
33333
44444
55555