UNIT-2
Assignment
Theory Questions
1. Define control flow in Python. Why is it important?
2. Differentiate between:
a) Simple Statement, Compound Statement, and Empty Statement
b) break, continue, and pass
3. Explain the purpose of the range() function with examples.
4. Write a short note on nested if statements with an example.
5. Compare for loop and while loop with suitable use cases.
6. Explain the use of else with loops. How is it different from else in if-else?
7. What are dictionaries in Python? How are they different from lists?
Coding Questions
Conditional Statements
8. Write a program to check whether a number is positive, negative, or zero.
9. Write a program to accept a student’s marks and display the grade (A, B, C, Fail) using if-elif-
else.
10. Write a program that checks if a person is eligible to vote in India (age ≥ 18 and citizen of
India).
Loops
11. Write a program using a for loop to print the multiplication table of a number.
12. Write a program using a while loop to print all odd numbers between 1 and 20.
13. Write a program to calculate the sum of digits of a given number.
14. Write a program that prints all letters of a given string in uppercase using a for loop.
Loop Control Statements
15. Write a program that prints numbers from 1 to 10 but skips 5 using continue.
16. Write a program that searches for a number in a list and stops when found using break.
17. Write a program that checks if a number exists in a list using a loop with else.
Lists and Dictionaries
18. Write a program to create a list of fruits, add a fruit, remove one, and print the final list.
19. Write a program to print all keys and values from a dictionary.
20. Write a program to calculate the total marks from a dictionary of subjects and marks.