These practice sets in the Python Mastery Hub are a carefully structured sequence of hands-on exercises designed to take absolute beginners from zero familiarity with Python to confident, independent coding. Each set focuses on a single core concept—starting with basics like variables and input/output, then progressing through strings, conditionals, loops, lists/tuples, sets/dictionaries, and finally functions—ensuring learners master one building block before moving to the next. These practice sets are essential because programming is a skill learned through active doing, not passive reading: repeated coding reinforces syntax, builds logical thinking, trains debugging instincts, and creates the muscle memory needed to write clean, functional code without constant reference. By working through these targeted questions in order, students gain genuine mastery and the confidence to tackle the repository’s Mega Tasks and console-based projects successfully.
-
Swap Numbers Without Extra Variable
Create two variables:a = 10andb = 20. Swap their values without using a third variable. Then print both variables to show the swap worked.Example output:
a = 20 b = 10
-
Swap City Names
Create two variables:city1 = "Lahore"andcity2 = "Karachi". Swap their values. Then print both variables.Example output:
city1 = Karachi city2 = Lahore
-
Add Two Numbers from User
Ask the user to enter two numbers (one number per input). Add them and print the sum.Example: If user enters `5` and `8`, output should be: `13`
-
Say Hello to User
Ask the user to enter their name. Print a greeting in this exact format:Hello Ali! -
Area of Rectangle
Ask the user for length and width (two numbers). Calculate area (length × width) and print:Area =followed by the answer.Example: Input `4` and `5` → `Area = 20`
-
Full Name Greeting
Ask the user for their first name and last name separately. Concatenate them and print a greeting likeHello, First Last!.Example: Input: `Ali`, `Sulman` → Output: `Hello, Ali Sulman!`
-
Welcome Message with Age
Ask for the user's name and age. Print a message:Welcome, [Name]! You are [Age] years old.. Use f-strings.Example: Input: `Ali`, `20` → Output: `Welcome, Ali! You are 20 years old.`
-
String Length Counter
Ask the user to enter any sentence. Print the total number of characters (including spaces).Example: Input: `Hello World` → Output: `Length: 11`
-
Upper and Lower Case
Ask for a string. Print it in all uppercase, then all lowercase.Example: Input: `Python is Fun` → Output: `UPPERCASE: PYTHON IS FUN` `lowercase: python is fun`
-
Name Formatting
Ask for first name and last name. Print:- Full name in normal case
- Full name in uppercase
- Full name in title case (first letter of each word capitalized)
Example: Input: `ali`, `sulman` → Output: `Normal: ali sulman` `UPPERCASE: ALI SULMAN` `Title Case: Ali Sulman`
-
Count Vowels
Ask the user for a word. Count and print how many vowels (a, e, i, o, u) it contains (case insensitive).Example: Input: `education` → Output: `Number of vowels: 5`
-
Reverse a String
Ask the user for a string. Print it in reverse order.Example: Input: `Python` → Output: `Reversed: nohtyP`
-
Simple Username Generator
Ask for first name and last name. Create a username by combining: first letter of first name (lowercase) + full last name (lowercase) + a random number (you can hardcode one like 123).Example: Input: `Ali`, `Sulman` → Output: `Username: asulman123`
-
Formatted Bill Message
Ask for item name, quantity, and price per item. Calculate total (quantity × price) and print a formatted bill:
Item: [Item]
Quantity: [Quantity]
Price per item: Rs.[Price]
Total: Rs.[Total]Example: Input: `Apple`, `5`, `50` → Output: `Item: Apple` `Quantity: 5` `Price per item: Rs.50` `Total: Rs.250`
-
Check Even or Odd
Ask the user to enter a number. Print whether it is even or odd.Example: Input: `4` → Output: `Even` Input: `7` → Output: `Odd`
-
Compare Two Numbers
Ask the user to enter two numbers. Print which one is greater (or if they are equal).Example: Input: `10` and `5` → Output: `10 is greater` Input: `8` and `8` → Output: `Both are equal`
-
Determine Age Category
Ask the user for their age. Print:Childif age < 13Teenagerif age is 13–19Adultotherwise
Example: Input: `10` → Output: `Child` Input: `16` → Output: `Teenager` Input: `25` → Output: `Adult`
-
Pass or Fail
Ask the user for their marks (out of 100). PrintPassif marks ≥ 40, otherwiseFail.Example: Input: `55` → Output: `Pass` Input: `35` → Output: `Fail`
-
Positive, Negative, or Zero
Ask the user to enter a number. Print whether it is positive, negative, or zero.Example: Input: `8` → Output: `Positive` Input: `-3` → Output: `Negative` Input: `0` → Output: `Zero`
-
Divisible by 3
Ask the user to enter a number. Check and print if it is divisible by 3 or not.Example: Input: `9` → Output: `Divisible by 3` Input: `10` → Output: `Not divisible by 3`
-
Assign Grade Based on Percentage
Ask the user for their percentage (0–100). Print the grade:A Gradeif ≥ 80B Gradeif 60–79C Gradeif 40–59Failotherwise
Example: Input: `85` → Output: `A Grade` Input: `45` → Output: `C Grade`
-
Day of the Week Message
Ask the user to enter a day of the week (e.g., "Monday"). Print a custom message:- Monday →
Start of the week! - Friday →
Weekend is near! - Saturday or Sunday →
Enjoy your weekend! - Any other →
Keep going!
Example: Input: `Friday` → Output: `Weekend is near!` Input: `Sunday` → Output: `Enjoy your weekend!`
- Monday →
-
Simple Calculator
Create a basic calculator:- Ask for two numbers.
- Ask for an operation (
+,-,*,/). - Use if/elif/else to perform the operation and print the result.
- Handle division by zero with a message like
Cannot divide by zero!.
Example: Inputs: `10`, `5`, `+` → Output: `Result: 15` Inputs: `20`, `4`, `/` → Output: `Result: 5.0` Inputs: `8`, `0`, `/` → Output: `Cannot divide by zero!`
Q1. Write a program using a while loop to print numbers from 1 to 10.
Q2. Write a program using a for loop to print numbers from 1 to 10.
Q3. Write a program using a loop to print even numbers from 1 to 20.
Q4. Write a program using a loop to print the table of 5 e.g. 5 x 1 = 5.
Q5. Write a program using a loop to print the sum of numbers from 1 to 10.
Q6. Write a program that takes a number from the user and prints numbers from 1 to that number.
Q7. Write a program that prints numbers from 10 to 1 using a loop.
Q9. Write a program to print given blow outputs using a loop:
1) 2) 3) 4) 05)
* * * * * * * 1 * * * * *
* * * * * * * * 1 2 * *
* * * * * * * * * 1 2 3 * *
* * * * * * * * * * 1 2 3 4 * *
* * * * * * * * * * * 1 2 3 4 5 * * * * *-
Create and Print a List
Ask the user to enter 5 favorite fruits (one by one). Store them in a list and print the complete list.Example: Inputs: `Apple`, `Banana`, `Orange`, `Mango`, `Grape` → Output: `['Apple', 'Banana', 'Orange', 'Mango', 'Grape']`
-
Access List Elements
Create a list of 5 numbers. Print the first, last, and middle element using indexing.Example: List: `[10, 20, 30, 40, 50]` → Output: `First: 10` `Middle: 30` `Last: 50`
-
List Slicing
Create a list of numbers from 1 to 10. Print:- First 5 elements
- Last 3 elements
- Elements from index 2 to 7
Example Output: `First 5: [1, 2, 3, 4, 5]` `Last 3: [8, 9, 10]` `Index 2 to 7: [3, 4, 5, 6, 7, 8]`
-
Modify List with Append and Insert
Start with an empty list. Ask the user for 3 items to add usingappend(). Then insert a new item at index 1 usinginsert(). Print the final list.Example: Inputs: `Book`, `Pen`, `Notebook` → Insert `Pencil` at index 1 → Output: `['Book', 'Pencil', 'Pen', 'Notebook']`
-
Remove Elements
Create a list:['Apple', 'Banana', 'Cherry', 'Banana']. Remove the first 'Banana' usingremove(), then remove the last element usingpop(). Print the list after each operation.Example Output: `After remove: ['Apple', 'Cherry', 'Banana']` `After pop: ['Apple', 'Cherry']`
-
List Operations
Ask the user for 5 numbers (one by one). Store in a list. Print:- Length of the list
- Sum of all numbers
- Maximum and minimum values
Example: Inputs: `10, 20, 30, 40, 50` → Output: `Length: 5` `Sum: 150` `Max: 50` `Min: 10`
-
Introduction to Tuples
Create a tuple of 5 days of the week. Print the tuple, its length, and access the 3rd day. Try to change one element (it should show an error — mention this in comments).Example: Tuple: `('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday')` → Output: `Tuple: ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday')` `Length: 5` `3rd Day: Wednesday`
-
Tuple Unpacking
Create a tuple with name, age, and city. Unpack it into three variables and print a message:Name: [name], Age: [age], City: [city].Example: Tuple: `('Ali', 20, 'Islamabad')` → Output: `Name: Ali, Age: 20, City: Islamabad`
-
Convert Between List and Tuple
Ask the user for 4 subjects. Store as a list. Convert to a tuple and print both. Then convert back to a list, add one more subject, and print the updated list.Example: Inputs: `Math`, `Physics`, `Chemistry`, `English` → Add `Computer` → Output: `Original List: ['Math', 'Physics', 'Chemistry', 'English']` `As Tuple: ('Math', 'Physics', 'Chemistry', 'English')` `Updated List: ['Math', 'Physics', 'Chemistry', 'English', 'Computer']`
Q1. Create a set of your favorite fruits and print it. Add "mango" to the set and print again.
Q2. Create a set of numbers from 1 to 5 and another set of numbers from 4 to 8. Print the common numbers using set operations.
Q3. Create a dictionary for a student with keys: name, age, grade. Print the dictionary.
Q4. Update the student dictionary to add a new key city and print the updated dictionary.
Q5. Write a program where the user can input a fruit name. If the fruit exists in your dictionary of fruits and their prices, print its price; otherwise print "Not available".
Q6. Create a set of your favorite movies. Remove one movie using discard() and print the set.
Q7. Create two dictionaries: dict1 = {'a': 1, 'b': 2} and dict2 = {'b': 3, 'c': 4}. Merge them and print the result.
Q8. Write a program to find unique words in a sentence entered by the user using a set.
Q9. Create a dictionary with subject names as keys and marks as values. Print all subjects where marks are above 50.
Q10. Write a program to count how many times each word appears in a sentence using a dictionary.
Q1. Write a function named greet() that prints:
Welcome to Python Programming
Q2. Write a function named show_name(name) that takes a name as a parameter and prints:
Hello <name>
Q3. Write a function named add_numbers(a, b) that takes two numbers and prints their sum.
Q4. Write a function named student_info(name, age) that prints the student’s name and age in one sentence.
Q5. Write a function named calculate_bill(price, quantity) that takes price and quantity and prints the total bill.
Q6. Write a function named is_even(number) that returns whether the number is even or odd.
Q7. Write a function named get_full_name(first_name, last_name) that returns the full name using string concatenation.
Q8. Write a function named find_max(a, b) that returns the greater number.
Q9. Write a function named count_items(items) that takes a list and returns the total number of items.
Q10. Write a function named show_menu() that prints a simple food menu and calls the function when the program runs.
Q11. Write a function named calculate_discount(price) that:
- Takes the product price as a parameter
- Applies a 10% discount
- Prints the final price after discount
Q12. Write a function named login_message(username) that:
- Takes a username as a parameter
- Prints a welcome message for that user
Q1. Create variables to store shop name and shop city and print them in one line.
Q2. Take user input for customer name and print a welcome message.
Q3. Create variables for item name and item price, then print them.
Q4. Concatenate customer name and item name to print:
<customer> is buying <item>
Q5. Take input for quantity and print a sentence using concatenation showing quantity and item name.
Q6. If quantity is greater than 5, print Bulk order, otherwise print Regular order.
Q7. If item price is greater than 1000, print Expensive item, else print Affordable item.
Q8. Take input for payment method (cash, card, online) and print a confirmation message based on input.
Q9. Use a loop to print item name quantity number of times.
Q10. Use a loop to print numbers from 1 to quantity.
Q11. Use a loop to calculate total price by adding item price quantity times.
Q12. Create a list named cart and add three item names to it.
Q13. Print all items in the cart using a loop.
Q14. Ask the user to enter an item name and check if it exists in the cart.
Q15. Create a tuple of available payment methods and print them.
Q16. Check whether the user’s selected payment method exists in the tuple.
Q17. Create a set from the cart list to remove duplicate items and print unique items.
Q18. Create a dictionary where:
- keys = item names
- values = item prices
Print the dictionary.
Q19. Use a loop to calculate the total bill from the dictionary.
Q20. Create a function named generate_bill() that:
- Takes customer name, cart dictionary, and payment method
- Prints customer name
- Prints all items with prices
- Prints total bill
- Prints payment confirmation message
Concepts: Variables, input/output, operators Description: Create a console-based calculator that performs addition, subtraction, multiplication, and division based on user choice. Skills Practiced:
input()/print()- Arithmetic operators
- Basic control flow
Concepts: Conditional statements, loops Description: The program generates a random number, and the user guesses until correct. Provide hints (higher/lower). Skills Practiced:
if / elif / elsewhilelooprandommodule
Concepts: Conditions, logical operators Description: Take marks as input and calculate grade (A, B, C, Fail) based on predefined rules. Skills Practiced:
- Conditional logic
- Comparison operators
- Input validation
Concepts: Loops Description: Generate a multiplication table for a given number up to a specified range. Skills Practiced:
forloop- Formatting output
- Iteration logic
Concepts: Lists, loops Description: Allow users to add, view, and remove tasks from a to-do list using a menu-driven program. Skills Practiced:
- Lists
- Menu-based programs
- Loop control
Concepts: Strings, conditions Description: Check whether a password meets criteria (length, digits, uppercase, special character). Skills Practiced:
- String methods
- Logical conditions
- Validation rules
Concepts: Functions, conditionals Description: Simulate ATM operations: check balance, deposit, withdraw, and exit. Skills Practiced:
- Functions
- State management
- Conditional branching
Concepts: Dictionary, functions Description: Store contacts with name and phone number. Support add, search, update, and delete operations. Skills Practiced:
- Dictionaries
- CRUD operations
- Function modularity
Concepts: Lists, dictionaries, loops Description: Create a quiz with multiple questions, track score, and show final results. Skills Practiced:
- Nested data structures
- Looping over data
- Scoring logic
Concepts: Functions, data structures, logic flow Description: Develop a small banking system with user accounts, login, balance tracking, and transaction history. Skills Practiced:
- Functions + dictionaries
- Program flow control
- Real-world problem modeling
