Python Problem Set
Table of Contents
1. Topic 1 – Basic Python
1.1. Outline
1.2. Problems (1–15)
2. Topic 2 – Conditional Statements
2.1. Outline
2.2. Problems (1–15)
3. Topic 3 – Loops
3.1. Outline
3.2. Problems (1–15)
4. Topic 4 – Lists
4.1. Outline
4.2. Problems (1–15)
Topic 1 – Basic Python
1.1 Outline
1. Understanding Code Comments
○ Single-line (# comment) and multi-line comments ('''...''' or """...""").
○ Importance of documentation for clarity.
2. Printing
○ Single, double, and triple quotes.
○ print() function parameters like sep and end.
○ Formatted strings (f-strings, .format()).
3. Variables & Data Types
○ Assigning values, updating variables.
○ Multiple assignments in one line.
○ Built-in types: int, float, str, bool.
4. Input Handling
○ Using input() to get user data.
○ Type conversion: int(), float(), etc.
5. Operators
○ Arithmetic: + - * / % // **.
○ Comparison: == != < > <= >=.
○ Logical: and, or, not.
6. Swapping Variables & Simple Tricks
○ Swapping without a temporary variable: a, b = b, a.
7. Basic Error Handling Approach
○ Checking if input is valid before processing (high-level concept for beginners).
1.2 Problems (1–15)
1. Comments & Print
Write a program that prints "Hello, Python!". Add a comment above that line describing what
the program does.
2. Single, Double, Triple Quotes
Print three lines: one using single quotes, one using double quotes, and one multi-line string
using triple quotes.
3. Variable Assignment and Update
Assign a numeric value to x, print it, then update x to another value and print again.
4. Multiple Assignments
Assign the value 100 to a, b, and c in one line. Then print them. Reassign distinct values to each
(a, b, c = 1, 2.5, "three") and print again.
5. Data Type Check
Create an integer num = 42, a float pi = 3.14, and a string msg = "Hello". Print each value and
print their types using type().
6. User Input & Display
Prompt the user for their favorite color. Print the color back in a sentence:
"Your favorite color is <color>!"
7. Sum of Two Integers
Ask the user for two integers. Convert them using int(). Print the result as:
"<num1> + <num2> = <sum>".
8. Arithmetic Operators
Let m = 15 and n = 4. Print the result of m + n, m - n, m * n, m / n, m % n, m // n, and m ** n.
9. Comparison Operators
Prompt the user for two integers p and q. Check and print whether p is greater, equal, or less
than q.
10.Logical Operators
Prompt for two integers. Check if both are positive (using and). Check if at least one is even
(using or). Print the results.
11.Floor Division vs. Floating Division
Ask the user for two integers. Print "a / b = result" and "a // b = result" side by side. Note the
difference.
12.Exponent Calculation
Prompt the user for a base and an exponent. Print the result of base**exponent.
13.Variable Swapping
Let a = 5 and b = 10. Print both before swapping, then swap them without a temp variable. Print
both again.
14.Formatted Print (Billing Example)
Let item = "Notebook" and price = 12.75. Print:
"Item: Notebook | Price: $12.75"
using an f-string or .format().
15.Simple Calculator (No Functions)
Prompt the user for two numbers and an operator (+, -, *, /). Perform the calculation and print
the result. Handle division by zero by printing an error message.
Topic 2 – Conditional Statements
2.1 Outline
1. if, elif, else Syntax
○ Basic structure for decision-making.
2. Nested if
○ Checking multiple layers of conditions.
3. Logical Operators
○ and, or, not within conditions.
4. Real-World Examples
○ Checking age, voting eligibility, day of the week, boiling point.
5. Common Mistakes
○ Indentation errors, missing : in if statements, incorrectly chaining comparisons.
2.2 Problems (1–15)
1. Voting Eligibility
Ask for age. If age ≥ 18, print "Eligible to vote" else "Not eligible to vote".
2. Largest of Three
Prompt for three numbers. Print the largest.
3. Boiling Point Check
Accept the temperature in Celsius. If ≥ 100, print "Water is boiling", otherwise "Not boiling".
4. Prime Check (Conditional Focus)
Prompt for an integer. If no divisors other than 1 and itself, print "Prime", else "Not prime".
(Minimal loop or direct conditions.)
5. Attendance
Ask for total_days and absent_days. Calculate attendance%. If < 75%, print "Cannot sit for
exam"; else print "Can sit for exam".
6. Triangle Type
Prompt for three sides a, b, c.
○ If all equal → "Equilateral"
○ If two equal → "Isosceles"
○ If all different → "Scalene"
7. Taxi Bill
Accept total km traveled.
○ First 10 km at ₹11/km
○ Next 90 km at ₹10/km
○ Beyond 100 km at ₹9/km
Print total.
8. Senior Citizen
Ask for age. If ≥ 60, print "Senior Citizen", else "Not Senior Citizen".
9. Vowel Check
Prompt for a single character. Check if it’s a, e, i, o, u (lower/upper). Print "Vowel" or "Not
vowel".
10.Even or Odd
Ask for a number. If % 2 == 0, print "Even", else "Odd".
11.Month Name
Prompt for a month number (1–12). Print corresponding month name (e.g., 1=January,
2=February). Print "Invalid month" otherwise.
12.Leap Year
Prompt for a year. If (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0), print "Leap Year",
else "Not a Leap Year".
13.Positive, Negative, Zero
Prompt for a number. Print "Positive" if > 0, "Negative" if < 0, or "Zero" if == 0.
14.Check Divisible by 3 and 5
Ask user for a number. If divisible by both 3 and 5, print "Divisible by 3 and 5". Else check if
divisible by only 3 or only 5. If neither, print "Not divisible by 3 or 5".
15.Simple Grade Calculator
Ask for a numeric percentage (0–100).
○ 80+ → "A"
○ 70–79 → "B"
○ 60–69 → "C"
○ Below 60 → "F"
Topic 3 – Loops
3.1 Outline
1. while Loops
○ Condition-based repetition.
○ Initializing and updating loop variables.
2. for Loops
○ Iteration over a range or sequence.
○ Common usage with range(start, stop, step).
3. Loop Control
○ break, continue to modify loop flow.
4. Nested Loops
○ Handling multi-level iteration (e.g., patterns).
5. Practical Uses
○ Summations, counters, prime checks, string traversal.
3.2 Problems (1–15)
1. Print 1 to 10
Use a while loop to print numbers from 1 to 10.
2. Sum 1 to N
Ask for N. Sum from 1 to N using a loop. Print the result.
3. Sum of Odd Numbers in a Range
Prompt for a start and end. Sum only the odd numbers between them.
4. Prime Check (Using Loops)
Prompt for an integer. Use a for or while loop to check if it’s prime. Print "Prime" or "Not prime".
5. Vowel Counter in a String
Ask user for a string. Use a loop to count the vowels (a, e, i, o, u). Print the total.
6. Digit Counter
Ask for an integer. Use a loop to count how many digits it has (e.g., 12345 → 5). Print the result.
7. Count Even Digits
Ask for an integer. Count only the digits that are even (0, 2, 4, 6, 8). Print the count.
8. Sum of Digits
Prompt for an integer. Sum all its digits. Print the result.
9. Sum of Odd Digits
Similar to above but add only the odd digits. Print the total.
10.Factorial of a Number
Prompt for a positive integer n. Compute n! using a loop. Print the result.
11.Multiplication Table
Prompt for a number. Print its table from 1 to 10 using a for loop.
12.FizzBuzz (1–30)
For each number from 1 to 30:
○ If divisible by 3, print "Fizz".
○ If divisible by 5, print "Buzz".
○ If divisible by both, print "FizzBuzz".
○ Otherwise, print the number itself.
13.Reverse a Number
Ask for an integer. Reverse its digits using a loop (e.g., 123 → 321) and print.
14.Palindrome Number Check
Ask for a number. Check if it reads the same forwards and backwards (e.g., 121, 12321). Print
"Palindrome" or "Not palindrome".
15.Print Star Pattern
Ask user for rows. Print the following pattern (if rows=5):
*
**
***
****
*****
Topic 4 – Lists
4.1 Outline
1. List Creation
○ Static literal (my_list = [1, 2, 3]).
○ From user input (loop + append()).
○ Using range() + list().
2. Accessing & Slicing
○ Indexing (list[0], list[-1]).
○ Slicing (list[start:end:step]).
3. Modifying Lists
○ append(), insert(), extend().
○ remove(), pop(), del.
○ Updating elements via index or slice assignment.
4. Searching & Counting
○ in keyword, .count(value).
○ max(), min(), sum().
5. Sorting & Reversing
○ .sort(), sorted().
○ .reverse(), slicing with [::-1].
6. Advanced
○ Removing duplicates.
○ List comprehension basics.
4.2 Problems (1–15)
1. Create List from User Input
Prompt the user for how many elements they want. Read each element (integer) and store in a
list. Print the list.
2. Sum of List Elements
Given a list of numbers (either hard-coded or from user), compute the total sum. Print it.
3. Sum of Odd Elements
From the same list, sum only the odd elements. Print the result.
4. Search in a List
Ask user for a number. Check if it’s in the list. Print "Yes" if found, otherwise "No".
5. Count Occurrences
Prompt user for a number to count in the list. Print how many times it appears.
6. Remove by Index
Ask the user for an index. Remove the element at that index (if valid) and print the updated list.
7. Remove by Value
Ask the user for a value to remove. If present, remove the first occurrence. Otherwise, print a
message stating it’s not found.
8. Find the Largest Number
Print the largest value in the list. (Try using max() or a manual loop.)
9. Count Even and Odd
Traverse the list. Count how many elements are even, how many are odd. Print both counts.
10.Separate Even and Odd into Two Lists
Create even_list and odd_list from the original list. Print both.
11.Sublist Using Slicing
Ask for start and end indices. Slice [start:end] from the original list and print the sublist.
12.Reverse Using Slicing
Print the reversed version of the list using [::-1].
13.Sort Ascending and Descending
Sort the list in ascending order. Print it. Then sort (or re-sort) it in descending order. Print again.
14.Second Largest Number
Find and print the second largest number in the list. (Hint: sorting or a manual approach.)
15.Remove Duplicates
If the list has duplicates, remove them. Print the new list with unique elements only.
Bonus: You can keep order or ignore it, but clarify your approach.