Python Practice Questions
If-Elif-Else
1. 1. Check Number Sign
- Ask the user for a number and print if it’s positive, negative, or zero.
2. 2. Login System
- Hardcode a username and password. Ask the user for both, and print:
- "Login successful" if both match
- "Wrong username" or "Wrong password" if only one is incorrect
- "Access denied" if both are wrong
3. 3. Simple Calculator
- Ask the user for two numbers and an operator (+, -, *, /). Use if-elif-else to perform
the correct operation.
List & Tuple
4. 1. Check Membership in List
- my_list = [2, 4, 6, 8]
- Ask the user for a number. Check if it’s in the list. Print "Found" or "Not found".
5. 2. Indexing Practice
- fruits = ["apple", "banana", "cherry"]
- Ask the user to enter 0, 1, or 2 and print the corresponding fruit. If invalid, print
"Invalid index".
6. 3. Compare First and Last Item of Tuple
- t = (5, 10, 15, 20, 5)
- Print "First and last are equal" or "Not equal".
Dictionary
7. 1. Phone Book Lookup
- phone_book = {"Alice": "1234", "Bob": "5678"}
- Ask the user for a name. Print the phone number if it exists. Otherwise, print "Not in
phone book".
8. 2. Subject Marks Evaluation
- marks = {"Math": 78, "Science": 88, "English": 65}
- Ask the user to enter a subject name. If it exists, print:
- "Pass" if marks ≥ 40
- "Fail" otherwise
- If subject not found, print "Subject not found".
Set Practice
9. 1. Is It a Weekend?
- weekend = {"Saturday", "Sunday"}
- Ask the user to enter a day of the week. Print "Weekend" or "Weekday".
10. 2. Element Belongs to Both Sets?
- A = {1, 2, 3}, B = {3, 4, 5}
- Ask the user for a number. Check if it’s in both sets. Print appropriate message.