Skip to content

alisulmanpro/Python-Mastery-Hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 

Repository files navigation

Python

License Status

This is a simple step-by-step Python learning hub for complete beginners. You start from zero and slowly become good at coding. We have 7 levels. Each level teaches one important topic with easy practice questions. Practice is the only way to learn coding well – do every question yourself. After the levels, try the 20 fun console projects to use everything you learned.


Image


Table of Contents


Set 1: Variables & Input/Output

Purpose
Learn how to store data in variables, take input from user, and print results. This is the first step of every Python program.

  1. Swap Two Numbers
    Define two numbers in variable. Swap them without extra variable. Print both after swap.

    Example: Input `First = 10` and `Second = 20` → Output: `First = 20`, `Second = 10`
  2. Swap Two Strings
    Take two strings from user. Swap them without extra variable. Print both after swap.

    Example: Input `First = "Ali"` and `Second = "Alia"` → Output: `First = "Alia"`, `Second = "Ali"`
  3. Add Two Numbers
    Ask user for two numbers. Add them and print the sum.

    Example: Input `5` and `8` → Output: `Sum = 13`
  4. Area of Rectangle
    Ask user for length and width. Calculate area and print it.

    Example: Input `4` and `6` → Output: `Area = 24`
  5. Say Hello to User
    Ask user for name. Print Hello [Name]!

    Example: Input `Ali` → Output: `Hello Ali!`
  6. Full Name Greeting
    Ask for first name and last name. Join them and print greeting.

    Example: Input `Alia` and `Mirza` → Output: `Hello, Alia Mirza!`
  7. Welcome with Age
    Ask for name and age. Print welcome message using f-string.

    Example: Input `Ali` and `20` → Output: `Welcome, Ali! You are 20 years old.`

Set 2: Strings

Purpose
Learn how to work with words and sentences. Almost every program needs text.

  1. String Length Counter
    Ask user for a sentence. Print how many characters it has.

    Example: Input `Hello Pakistan` → Output: `Length: 14`
  2. Upper and Lower Case
    Ask for a string. Print it in uppercase and lowercase.

    Example: Input `Python` → Output: `UPPER: PYTHON`, `lower: python`
  3. Name Formatting
    Ask first and last name. Print normal, uppercase, and title case.

    Example: Input `lilly`, `collins` → Output: `Normal: lilly collins`, `Title Case: Lilly Collins`
  4. Formatted Bill
    Ask item name, quantity, price. Print neat bill with total.

    Example: Input `Apple`, `5`, `50` → Output:  
    `Item: Apple`  
    `Quantity: 5`  
    `Total: Rs.250`

Set 3: If/Elif/Else - Conditionals

Purpose
Learn how to make your program choose different actions using if/elif/else.

  1. Even or Odd
    Ask a number. Print Even or Odd.

    Example: Input `7` → Output: `Odd`
  2. Compare Two Numbers
    Ask two numbers. Print which is bigger or if equal.

    Example: Input `10` `5` → Output: `10 is greater`
  3. Pass or Fail
    Ask marks. Print Pass (≥40) or Fail.

    Example: Input `35` → Output: `Fail`
  4. Count Vowels
    Ask for a word. Count vowels (a,e,i,o,u – ignore case).

    Example: Input `education` → Output: `Number of vowels: 5`
  5. Positive, Negative, Zero
    Ask a number. Print what it is.

    Example: Input `-4` → Output: `Negative`
  6. Grade System
    Ask percentage. Print A (≥80), B (60-79), C (40-59), Fail.

    Example: Input `85` → Output: `A Grade`
  7. Simple Calculator
    Ask two numbers and operation (+ - * /). Print result. Show error for divide by zero.

    Example: Input `10`, `5`, `/` → Output: `Result: 2.0`

Set 4: Loops

Purpose
Learn how to repeat work easily using while and for loops.

  1. Print 1 to 10
    Use for loop to print numbers 1 to 10.

  2. Multiplication Table
    Ask a number. Print its table (1 to 10).

    Example: Input `5``5 x 1 = 5` ... `5 x 10 = 50`
  3. Sum of Numbers
    Ask a number n. Print sum from 1 to n.

    Example: Input `10` → Output: `Sum = 55`
  4. Even Numbers 1-20
    Print all even numbers from 1 to 20 using loop.

  5. Countdown
    Print numbers from 10 down to 1 using while loop.

  6. Simple Star Pattern
    Print this pattern using loops:

    *                 1
    * *               1 2
    * * *             1 2 3
    * * * *           1 2 3 4
    * * * * *         1 2 3 4 5

Set 5: Lists & Tuples

Purpose
Learn how to store many items in lists (can change) and tuples (cannot change).

  1. Create Fruit List
    Ask user for 5 fruits. Store in list and print.

  2. Access List Items
    Make list [10,20,30,40,50]. Print first, middle, last.

  3. Add and Insert Items
    Start empty list. Append 3 items. Insert one at position 1. Print final list.

  4. List Slicing
    Make list 1 to 10. Print first 5, last 3, and items 3 to 8.

  5. Introduction to Tuples
    Make tuple of 5 days. Print it and try to change one item (will give error).

  6. Convert List to Tuple
    Ask 4 subjects → store in list → convert to tuple → print both.


Set 6: Sets & Dictionaries

Purpose
Learn sets (unique items) and dictionaries (key-value pairs).

  1. Create and Add to Set
    Make empty set. Add 5 numbers. Print set (duplicates removed).

  2. Set Operations
    Make two sets. Print union and intersection.

  3. Remove from Set
    Make set with 6 items. Remove one and discard one (if not exist). Print after each.

  4. Student Marks Dictionary
    Make dict with 3 student names and marks. Print all.

  5. Add and Update Dict
    Start empty dict. Add 3 key-value pairs. Update one value.

  6. Word Frequency
    Ask a sentence. Make dict to count how many times each word appears.


Set 7: Functions

Why this level?
Learn how to make functions so you can use same code again easily.

  1. Add Two Numbers Function
    Make function add(a, b) that returns sum. Call it and print.

  2. Check Even/Odd Function
    Make function is_even(num) that returns True or False. Use it.

  3. Maximum of Three
    Make function max_of_three(a,b,c) that returns biggest number.

  4. Factorial Function
    Make function factorial(n) using loop. Return n!.

  5. Greeting Function
    Make function greet(name, age) that prints welcome message.

  6. Area Calculator Function
    Make function area(shape, values) that calculates rectangle or triangle area.


Set 8: Object Oriented Programming - Classes & Objects

Purpose
Learn the basics of OOP. Create your own classes, objects, and attributes. This is the foundation of modern programming.

  1. Create a Simple Class
    Define a class named Dog with no attributes or methods. Create an object called my_dog. Print the type of my_dog.

    Example: print(type(my_dog)) → Output: <class '__main__.Dog'>
  2. Add Attributes to Object
    Using the same Dog class, create my_dog and add two attributes: name = "Buddy" and age = 5. Print both attributes.

    Example: print(my_dog.name) and print(my_dog.age) → Output: Buddy 5
  3. Multiple Objects
    Create two objects of Dog class: dog1 and dog2. Give different name and age to each. Print names of both.

  4. Class Attribute
    Add a class attribute species = "Canine" to Dog class (outside init). Create any object and print dog.species. It should work for all objects.

  5. Modify Attribute
    Create a class Car. Create car1 object. Add color = "Blue". Print color, then change it to "Red" and print again.

  6. Empty Class with Pass
    Create a class Student using pass keyword. Create object, add name and roll_no attributes manually. Print both.


Set 9: Constructors and Methods

Purpose
Learn how to use init constructor and define methods inside classes. Make your objects more powerful.

  1. Constructor with init
    Create a class Person with init(self, name, age). Create object p1 and print name and age.

    Example: p1 = Person("Ali", 25)

print(p1.name) → Output: Ali

  1. Method Inside Class
    In Person class, add a method greet(self) that prints "Hello, my name is [name]". Call the method on p1.

  2. Method with Parameters
    Add a method birthday(self) in Person that increases age by 1. Call it and print new age.

  3. Multiple Methods
    Create a class Calculator with init and two methods: add(self, a, b) and multiply(self, a, b). Create object and call both.

  4. String Representation
    In Dog class (from previous), add str(self) method that returns "Dog named [name], age [age]". Print the object.

  5. Bank Account Example
    Create class BankAccount with init(self, balance=0), deposit(self, amount) and withdraw(self, amount). Test deposit and withdraw.


Set 10: Inheritance and Polymorphism

Purpose
Learn inheritance, method overriding, and basic polymorphism. Reuse code like a pro.

  1. Simple Inheritance
    Create class Animal with eat(self) method. Create class Dog(Animal). Create dog object and call eat().

  2. Method Overriding
    In Dog class, override eat(self) to print "Dog is eating bones". Create dog object and call eat().

  3. Using super()
    Add init in Animal (name). In Dog use super() to set name. Add bark(self) method. Test both.

  4. Multiple Child Classes
    Create Cat(Animal) and Dog(Animal). Give each their own sound method. Create objects and call sound().

  5. Polymorphism Example
    Create a function make_sound(animal) that calls animal.sound(). Pass Dog and Cat objects to it.

  6. Real World Example
    Create class Vehicle with move(self). Create Car(Vehicle) and Bike(Vehicle) with different move messages. Test both.


Python Projects

1. Number Guessing Game

Skills: variables, loops, conditionals, random, input validation, functions.

Milestones

  • V1 (starter): Computer picks 1–100, student guesses, give higher/lower hints, track attempts.
  • V2 (required): Add input validation, allow multiple rounds, show best score (fewest attempts).
  • Stretch (self-learn): Add difficulty levels (range changes), timer, and persistent high-score file.
    Starter hint: import randomsecret = random.randint(1,100); loop until guessed.
    Quick tests: guess correctly in N attempts; invalid input doesn't crash.

2. Simple Calculator (CLI)

Skills: functions, exception handling, parsing strings, loops.

Milestones

  • V1: Support + - * / for two numbers via input prompts.
  • V2: Support chaining operations, handle divide-by-zero and bad input.
  • Stretch: implement expression parsing (e.g., "3 + 4 * 2") or REPL mode.
    Starter hint: separate parse_input(), compute(a, op, b) functions. Use try/except.
    Quick tests: 3/0 handled gracefully; "abc" prompts again.

3. To-Do List with File Save/Load

Skills: lists, file I/O (text or JSON), CRUD operations, functions.

Milestones

  • V1: add/view/remove tasks stored in memory.
  • V2: save/load tasks to a JSON/text file so tasks survive program restart.
  • Stretch: search/filter tasks, mark priority, and sort by date added.
    Starter hint: use json module: write tasks (list of dicts) to disk.
    Quick tests: add task → saved file contains task; restart program → tasks loaded.

4) Contact Book (CSV or JSON)

Skills: dictionaries, lists, file I/O, simple validation, search.

Milestones

  • V1: basic add/view/search by name (in-memory).
  • V2: persist using CSV/JSON; update/delete contact.
  • Stretch: export/import VCF, or search fuzzy matches.
    Starter hint: store each contact as { "name":..., "phone":..., "email":... } and use list comprehension for search.
    Quick tests: add → find by name; remove → no longer found; file persists.

5) Mad Libs / Story Generator

Skills: strings, concatenation, user input, functions, lists.

Milestones

  • V1: ask for a few words and print the story.
  • V2: support multiple story templates chosen by user.
  • Stretch: read templates from files, randomize templates, or add grammar checks.
    Starter hint: use placeholders like {noun} and .format(**answers).
    Quick tests: given inputs, output contains those words in expected places.

6) Dice Rolling Simulator + Probability Estimator

Skills: random, loops, counters, basic plotting (optional), statistics.

Milestones

  • V1: Simulate rolling N dice and show outcomes counts.
  • V2: Run many trials, show empirical probabilities and compare to expected.
  • Stretch: Display histogram (matplotlib optional) and let user choose dice types.
    Starter hint: Collections.Counter is handy for counts.
    Quick tests: 6-sided die → approx 1/6 frequency in many trials (students can see convergence).

7) Expense Tracker (CLI)

Skills: lists/dicts, file I/O (CSV/JSON), aggregation, date handling (optional).

Milestones

  • V1: Add expense (amount + category) and show total per run.
  • v2: Persist to CSV, show totals per category and monthly totals.
  • Stretch: Import bank CSV, filter by date ranges.
    Starter hint: Represent each record as {"amount":float, "cat":str, "date": "YYYY-MM-DD"}; use csv or json.
    Quick tests: Add entries → category totals correct.

8) CLI Quiz System (question bank JSON)

Skills: JSON, loops, input validation, scoring, functions.

Milestones

  • V1: Ask 5 questions from an in-memory list; compute score.
  • V2: Load questions from JSON, randomize order, show correct answers at end.
  • Stretch: Timed questions, multiple users, and persistent user scores.
    Starter hint: JSON schema: {"q":"...", "options":["a","b"], "answer":0}.
    Quick tests: Scoring matches expected answers; JSON loads properly.

9) FizzBuzz Variants & Pattern Printing (algorithmic thinking)

Skills: loops, conditionals, modulo arithmetic, nested loops for patterns.

Milestones

  • V1: Classic FizzBuzz (print 1..N with rules).
  • V2: Extend rules (e.g., multiple keyword mapping), and write unit tests.
  • Stretch: Generate ASCII shapes (pyramids) and analyze complexity (O(n), O(n^2)).
    Starter hint: Use modular checks in order (if i % 15 == 0 before %3/%5).
    Quick tests: Known sequences for first 20 values.

10) Word Frequency Counter (file input)

Skills: file I/O, string processing, dicts, sorting.

Milestones

  • V1: Read a text file and output top-10 words.
  • V2: Ignore stopwords/punctuation, case-insensitive, show counts.
  • Stretch: Build concordance or show sentence locations for top words.
    Starter hint: Normalize text (.lower()), remove punctuation (str.translate) and use Counter.
    Quick tests: For short sample file, expected top words & counts.

11) Simple Bank Account Simulator (state and simple OOP optional)

Skills: functions, state management, optional classes, input validation.

Milestones

  • V1: Simulate deposit/withdrawal and show balance (functional style).
  • V2: Add transaction history (list) and persist to JSON.
  • Stretch: Convert to Account class, support multiple accounts and transfers.
    Starter hint: Start with procedural approach before introducing class Account: as a stretch.
    Quick tests: Deposits and withdrawals update balance; cannot withdraw over balance.

12) Shape Area Calculator (Polymorphism)

Skills: inheritance, polymorphism, methods, math module.

Milestones

  • V1: Circle and Rectangle classes, each with calculate_area() method.
  • V2: Base Shape class + list of shapes; loop to show and sum all areas.
  • Stretch: Add Triangle class; menu to add any shape and display total area.
    Starter hint: Override calculate_area() in each child class. Store shapes in a list and use polymorphism.
    Quick tests: Circle (πr²), Rectangle (length×width), Triangle (0.5×base×height) calculate correctly.

13) Employee Payroll System (Inheritance & Polymorphism)

Skills: classes, inheritance, polymorphism, dictionaries.

Milestones

  • V1: Employee base class with name, base_salary and get_info() method.
  • V2: Manager and Developer classes inherit and override get_salary() (add bonus).
  • Stretch: Company class to manage list of employees, calculate total payroll and display all.
    Starter hint: Use super().init() in child classes. Override get_salary() for different types.
    Quick tests: Different employee types show correct salary; total payroll sums all employees correctly.

14) Zoo Animal Management System (Inheritance & Polymorphism)

Skills: classes, inheritance, polymorphism, lists, JSON.

Milestones

  • V1: Animal base class with name, species and make_sound() method. Create Lion and Elephant subclasses overriding the sound.
  • V2: Zoo class to add animals, display all and call sounds using polymorphism.
  • Stretch: Add feed() method (different food per animal type) and save entire zoo to JSON.
    Starter hint: Use super().init() in child classes. Keep animals in a list and loop to demonstrate polymorphism.
    Quick tests: Each animal makes its correct sound; Zoo can list and feed all animals without errors.

15) Pizza Ordering System (Composition & Polymorphism)

Skills: classes, composition, polymorphism, input validation.

Milestones

  • V1: Pizza base class with size, toppings list and calculate_price() method.
  • V2: Order class (composition) to hold multiple pizzas, show cart and total price.
  • Stretch: VegPizza and NonVegPizza subclasses with extra charges; full menu + save order to JSON.
    Starter hint: Order class should have a list of Pizza objects. Override calculate_price() in subclasses for extra cost.
    Quick tests: Total price updates correctly with different pizza types; cannot add pizza without size or toppings.

Django Projects

1) Personal Portfolio Website with Blog & Project Showcase

Skills: models, templates, forms, authentication, static/media files, admin customization.

Milestones

  • V1: Static-like homepage with About, Skills, Projects sections (projects from database).
  • V2: Add Blog app (Post model with categories/tags), contact form that sends email, visitor counter.
  • Stretch: Dark/light mode toggle, project detail page with screenshots/gallery, admin dashboard stats (views, messages).
    Starter hint: Use one custom User model or extend AbstractUser. Store projects & posts in separate models.
    Quick tests: Contact form sends real email; projects and blog posts display correctly; responsive design looks good on mobile.

2) Event Registration System

Skills: models, forms, email, authentication, date fields, permissions.

Milestones

  • V1: Event model (title, date, venue, capacity) + list/detail views + simple registration form.
  • V2: User login required to register, track "My Registrations", show remaining spots.
  • Stretch: Waitlist when full, QR code generation for tickets, organizer dashboard, email reminders.
    Starter hint: Use DateTimeField + custom clean() in form to check capacity. Send email on successful registration.
    Quick tests: Spots decrease on registration; cannot register when full; user sees only their events.

3) Job Board Portal

Skills: models, forms, authentication, pagination, filtering, file upload.

Milestones

  • V1: Job model (title, company, description, salary range) + list/detail + search by keyword.
  • V2: Employer role can post jobs, candidate role can apply with profile + resume upload.
  • Stretch: Advanced filters (location, experience, job type), application status tracking, email notifications.
    Starter hint: Use groups or custom user profile model to separate Employer/Candidate. Use FileField for resumes.
    Quick tests: Only employers post jobs; candidates see application history; filters narrow results accurately.

4) Book Review & Reading Tracker Platform

Skills: models, ManyToMany, forms, authentication, ratings, image upload.

Milestones

  • V1: Book model (title, author, cover image, genre) + list/detail + simple review form.
  • V2: User can add books to "Reading List" / "Read" / "Wishlist", rate & review books (1–5 stars).
  • Stretch: Average rating display, recommendation engine (based on genre/ratings), progress tracker (pages read).
    Starter hint: Use ManyToManyField for user-book relationships with through model for status & rating.
    Quick tests: Ratings update average correctly; user sees personalized lists; cover images load properly.

5) Freelance Service Marketplace (Mini Upwork-style)

Skills: models, forms, authentication, file upload, search, messages/notifications.

Milestones

  • V1: Service/Gig model (title, description, price, category) posted by freelancers + browse/list view.
  • V2: Clients can place orders (with requirements file upload), freelancers see their orders.
  • Stretch: Review/rating system after completion, messaging between client & freelancer, categories + search/filter.
    Starter hint: Separate Freelancer and Client profiles. Use Order model with ForeignKeys to Gig and User.
    Quick tests: Orders link correct gig & user; only logged-in users can order/message; ratings visible on profile/gig.

About

Structured Python practice hub for beginners learning Programming Fundamentals (PF). Features 7 sequenced question sets, 20 mega tasks, and 10 console projects to master variables, conditionals, loops, lists, functions & more through hands-on coding.

Topics

Resources

License

Stars

Watchers

Forks

Contributors