Python assignments
Python assignments
1. Basic Printing
Write a loop to print numbers from 1 to 10.
2. Even Numbers
Print all even numbers between 1 and 20 using a loop.
3. Sum of Numbers
Calculate the sum of numbers from 1 to 50 using a loop.
4. Multiplication Table
Print the multiplication table of 5.
5. Factorial
Calculate the factorial of a given number using a loop.
6. Count Digits
Write a loop to count the number of digits in a given number.
7. Reverse a String
Reverse a given string using a loop.
---
---
---
---
---
---
---
---
---
---
---
---
---
These assignments cover a wide range of basic programming tasks, including loops,
conditionals, string manipulation, and mathematical calculations. They’re designed to build
comfort with Python’s syntax and fundamental operations. Let me know if you want hints or
further breakdowns for any of these!
Here are some additional beginner Python assignments to keep you practicing:
---
### 1. **FizzBuzz**
- Write a program that prints numbers from 1 to 50. For multiples of 3, print "Fizz" instead of
the number, and for multiples of 5, print "Buzz." For numbers that are multiples of both 3 and 5,
print "FizzBuzz."
---
---
---
---
### 5. **Password Strength Checker**
- Write a program that checks if a user’s password is strong. Ask the user for a password, and
check if it meets these conditions: at least 8 characters, contains at least one number, and
contains both uppercase and lowercase letters. Inform the user if the password is strong or
weak.
---
---
---
---
---
---
---
### 12. **Sum of a Range**
- Write a program that asks the user for a starting number, an ending number, and a step
value. Using a loop, calculate and print the sum of all numbers from the starting number up to
but not including the ending number, with the specified step.
---
---
---
---
---
---
---
---
These assignments will give you plenty of opportunities to work with Python’s core concepts,
such as loops, conditionals, lists, and string manipulation. Let me know if you need more
specific guidance on any of these!
Here are some beginner-level Python assignments to practice loops, along with `break`,
`continue`, and `else` statements:
i = 10
while i > 0:
print(i)
i -= 1
else:
print("liftoff!")
for i in range(1,20):
if i % 2 == 0:
continue
print(i)
### 3. Sum of Numbers
Write a `while` loop that keeps asking the user to enter a number. Add each number to a
running total. If the user enters 0, break the loop and print the total sum of the numbers entered.
i=0
while True:
n = int(input("enter a number: "))
if n == 0:
break
i += n
print(i)
Here are beginner-level Python assignments for each topic you've listed. These will help you get
hands-on practice with fundamental Python concepts.
---
---
Each assignment encourages exploration of a core Python concept. Let me know if you need
any explanations or solutions!
---
---
These exercises will help you practice variable declaration, assignment, and manipulation in
Python! Let me know if you'd like any explanations or hints.
Here are beginner-level Python assignments combining **data types** and **variables** to
deepen your understanding of both:
---
---
These assignments focus on practicing with data types and variables, including string
manipulation, arithmetic operations, and type conversion. Let me know if you need hints or
solutions for any of them!
Here are real-world inspired Python assignments focusing on **data types** and **variables**:
---
---
These assignments will make data types and variables feel more relevant to real-world
situations. Let me know if you need any guidance with these!
Here are real-world inspired Python problems focused on practicing **conditional statements**:
---
These problems will help you practice using `if`, `elif`, and `else` statements in various real-life
scenarios. Let me know if you need any help with solutions or explanations!
Here are five beginner-friendly Python project ideas to help you learn key programming
concepts:
Let me know if you’d like further details on any of these or if you want hints on starting them!
Here are five more beginner Python project ideas that will help you deepen your understanding
of programming concepts:
Here are a few examples of programs that would likely require around 100 lines of code or
more, providing a good challenge and covering the skills employers look for:
These projects will help you practice multiple aspects of Python programming while working with
real-world scenarios, which is invaluable for job preparation. Let me know if you need help
starting any of them!
Here are a few more beginner-friendly Python projects that can be expanded to around 100
lines and beyond, helping you cover a range of practical skills:
Here are 10 Python project ideas that showcase different skills and are great for job
interviews. Each project demonstrates real-world problem-solving and practical application of
Python concepts:
● Project: Develop a script that automates a repetitive task, like renaming multiple files,
scraping data from websites, or generating email reports.
● Tech: Use os, shutil, and selenium or beautifulsoup4 for web scraping.
● Example: A script to download stock prices and generate a daily report in Excel using
openpyxl.
● Project: Create a program that analyzes sales or user data and displays visualizations.
● Tech: Use pandas for analysis and matplotlib or seaborn for visualization.
● Example: Analyze e-commerce data (orders, revenue) and create graphs of trends.
● Project: Build a tracker where users can log expenses, categorize them, and view
monthly summaries.
● Tech: Use Tkinter for a GUI or Flask for a web-based solution.
● Example: Save expense data in a CSV or SQLite database and generate monthly
reports.
4. API Integration Project (Skill: Working with APIs)
● Project: Build an application that consumes data from public APIs, such as weather
forecasts, movie databases, or financial APIs.
● Tech: Use requests to fetch data and process it.
● Example: A weather app that shows a 7-day forecast and sends alerts for bad weather.
● Project: Build a chatbot that can answer FAQs or hold simple conversations.
● Tech: Use NLTK, spaCy, or transformers for natural language processing.
● Example: A chatbot that assists with customer support or provides restaurant
recommendations.
● Project: Develop a scraper to collect data from a website, such as job postings, product
prices, or news articles.
● Tech: Use BeautifulSoup or Scrapy.
● Example: Scrape prices from e-commerce websites and notify users of price drops.
● Project: Create a secure password manager that stores encrypted passwords for
different accounts.
● Tech: Use cryptography for encryption and a database like SQLite for storage.
● Example: Provide a CLI or GUI interface for managing accounts securely.
● Project: Build a simple machine learning model, like predicting house prices or customer
churn.
● Tech: Use scikit-learn for model building and matplotlib for visualizations.
● Example: Train a model to classify emails as spam or non-spam.
● Project: Create a Python program that generates a static portfolio website for
developers based on user input.
● Tech: Use Jinja2 for templates and Flask for backend.
● Example: Users input their skills and projects, and the app generates an
HTML/CSS-based portfolio.
1. Choose a Relevant Domain: Tailor the project to align with the company’s industry.
2. Showcase Modular Code: Use functions, classes, and clean code practices.
3. Highlight Scalability: Show how the project can be extended or improved.
4. Document Well: Provide a README file with installation and usage instructions.
5. Deploy Your Projects: Use platforms like GitHub, Heroku, or Streamlit to demonstrate
live projects.
Here are a few beginner Python program ideas, similar to the To-Do List program, to help you
practice and strengthen your skills:
1. Simple Calculator
Objective: Create a simple calculator that performs basic operations (addition, subtraction,
multiplication, division).
Features:
Objective: Create a guessing game where the computer randomly picks a number, and the
player has to guess it. After each guess, provide feedback ("too high", "too low", or "correct").
Objective: Create a simple contact book that allows the user to add, view, and search for
contacts by name.
Objective: Create a program that asks the user to vote for one of three candidates. After voting,
display the total number of votes each candidate received.
5. Palindrome Checker
Objective: Create a program that checks if a word entered by the user is a palindrome (i.e., a
word that reads the same forward and backward).
Objective: Simulate an ATM where the user can check their balance, deposit money, or
withdraw money. It keeps track of the balance.
Objective: Calculate the average grade of a student from a list of grades they enter.
Here are some simpler Python programs that are great for beginners to practice the basics like
input/output, loops, conditionals, and data manipulation:
8. MARKSHEET PROGRAM
Objective: Calculate the sum of all natural numbers up to the entered number n.
Objective: Print all even numbers between 1 and the entered number n.
Objective: Check if the entered word is a palindrome (reads the same forward and backward).
INTERMEDIATE OR ADVANCED :
Here are 5 Python assignments that go beyond the basics, involving intermediate to advanced
concepts:
● Concepts Covered: Working with APIs, JSON Parsing, External Libraries (Requests),
Error Handling
● Description: Create a program that fetches real-time weather data from an open
weather API (like OpenWeatherMap) and displays the current weather for a city entered
by the user.
● Requirements:
○ Use the requests library to interact with an API and fetch weather data.
○ Parse the JSON response to extract temperature, humidity, weather conditions,
etc.
○ Allow the user to input a city name and display the current weather information.
○ Handle errors gracefully (e.g., if the city is not found or the API request fails).
Here’s a detailed 12-week plan with daily exercises for consistent practice:
Day 2:
● Input two numbers and display their sum, difference, product, and quotient.
● Write a program to check if a number is positive, negative, or zero.
Day 3:
Day 4:
Day 5:
Day 6:
● Solve 5 problems using loops (e.g., print numbers 1–10, calculate the sum of first N
numbers).
Day 7:
Day 1:
● Write a program to check if a number is prime.
● Practice nested loops with patterns (e.g., a pyramid).
Day 2:
Day 3:
Day 4:
Day 5:
Day 6–7:
Week 3: Lists
Day 1:
Day 2:
Day 3:
Day 4:
Day 5–7:
● Mini-project: Create a grocery list manager with features to add, remove, and display
items.
Day 1:
Day 2:
Day 3:
Day 4–7:
● Mini-project: Develop a text analyzer that reads a paragraph and counts words, vowels,
and unique words.
Week 5–6: Functions and Modules
Day 1:
Day 2:
Day 3–4:
Day 5–6:
Day 1:
Day 2–3:
Day 4–7:
● Mini-project: Develop a student record system with file storage (add, view, and delete
records).
Day 1:
Day 2:
Day 3–4:
Suggestions:
LIST
Here are some exercises to help you practice working with lists in Python:
Exercise 1: Create a list of numbers and find the largest and smallest
numbers
● Create a list.
● Check if the list is empty and print a message saying "The list is empty" or "The list is not
empty."
TUPLE
○ Create a tuple with nested tuples inside it. Access specific elements within the
nested tuples.
○ Extract a nested tuple and print its first and last element.
5. Tuple Slicing
○ Create a tuple of 10 numbers. Slice it to get the first half and the second half.
○ Extract every third element from a tuple.
6. Tuple Unpacking
○ Convert a tuple of strings into a list. Add an element to the list, then convert it
back into a tuple.
○ Create a tuple of numbers. Convert it to a list, sort it, and then convert it back into
a tuple.
9. Tuples as Keys
○ Create a dictionary where keys are tuples representing coordinates (x, y), and
values are colors.
○ Access the color of a specific coordinate using the tuple as a key.
10.Mathematical Operations
○ Create a tuple of integers. Calculate the sum of all elements in the tuple.
○ Find the difference between the maximum and minimum values in the tuple.
11.Zipping Tuples
○ Pair two tuples: one containing names and another containing ages. Create a list
of tuples representing each name with its corresponding age.
12.Tuple Comparison
○ Compare two tuples element by element to find out which one is larger.
○ Compare tuples of different lengths and predict the result.
13.Immutable Property
○ Create a tuple and try adding, deleting, or modifying its elements. Observe and
explain the results.
14.Tuple Nesting Challenge
○ Create a tuple of tuples. Each inner tuple should contain a student’s name and
their scores in three subjects.
○ Access a specific student’s scores and calculate their average.
15.Real-World Application
○ Imagine a system where tuples store a product ID, name, and price. Create
tuples for five products.
○ Extract all product names and prices from the tuples.
DICTIONARIES
○ Create a dictionary to store the names of five students and their corresponding
grades.
○ Access the grade of a specific student by their name.
○ Try to update the grade of a student and add a new student to the dictionary.
2. Key and Value Extraction
○ Extract and print all keys and values from a dictionary of countries and their
capitals.
○ Print all items (key-value pairs) from a dictionary.
3. Membership Check
○ Check if a specific key (e.g., "apple") exists in a dictionary of fruits and their
prices.
○ Check if a particular value (e.g., 100) exists in the dictionary.
4. Iterating Through a Dictionary
○ Create a dictionary of students and their scores. Iterate over the dictionary to
print each student’s name and score.
○ Use a loop to calculate the average score of all students.
5. Nested Dictionaries
○ Create a dictionary where each key is a product ID, and each value is another
dictionary containing the product’s name, price, and stock quantity.
○ Access the price of a specific product using its ID.
6. Updating Dictionaries
○ Create a dictionary with three keys: "morning", "afternoon", and "evening," each
with a corresponding activity as a value.
○ Update the "morning" activity and add a new key for "night."
7. Removing Items
○ Write a program to count the frequency of each letter in a given word using a
dictionary.
○ Create a dictionary to count how many times each color appears in a list of
colors.
9. Default Values
○ Use the get() method to access values safely from a dictionary of animals and
their habitats.
○ Attempt to access a non-existent key and provide a default message.
10.Merging Dictionaries
○ Combine two dictionaries: one containing names and another containing ages.
○ Merge two dictionaries of items and their prices, ensuring no data is lost.
11.Sorting and Filtering
○ Create a dictionary of products and their prices. Sort the dictionary by price
(ascending).
○ Filter out products with a price below a certain threshold.
12.Using Tuples as Keys
○ Create a dictionary where keys are tuples representing coordinates (x, y), and
values are descriptions of locations.
○ Access a description using a specific coordinate tuple.
13.Real-World Application
○ Design a dictionary to store a library's book data. Each key should be a book title,
and each value should be the author’s name.
○ Add, update, and remove books from the dictionary.
14.Frequency Count
○ Create a dictionary to count how many times each word appears in a given
sentence.
○ Count the frequency of numbers in a list and store the results in a dictionary.
15.Complex Data Structures
○ Design a dictionary where each key is a student’s name, and each value is a
dictionary containing their age, grade, and subjects they study.
○ Access a specific student’s subjects and update their grade.
16.Mapping and Transformations
○ Create a dictionary where keys are categories (e.g., "fruits", "vegetables"), and
values are lists of items in those categories.
○ Add new items to a specific category and remove an item from another category.
19.Error Handling with Dictionaries
Here are a few long Python program prompts to practice creating flowcharts:
5. ATM Simulator
Develop a system to manage inventory for a small store. The system should:
● Allow the user to add, remove, and update product details (name, price, quantity).
● Track stock levels and generate alerts for low stock.
● Generate reports of all inventory items with their current quantities and values.
● Save inventory data to a file for persistence.
Create a program that manages a list of items in a **shopping cart**. The program should
provide the user with the following options:
---
#### **Instructions:**
- Remove the item if it exists. Handle cases where the item is not in the cart.
- Prompt the user for an item to search for. Indicate whether the item is in the cart or not.
---
- Save the cart to a file and load it when the program starts.
---
#### **What You'll Practice:**
- Adding (`append`)
- Clearing (`clear`)
Here are some beginner exercises that use only strings manipulation, operators, and if-else
statements:
1. Palindrome Checker
Write a program that checks if a given word is a palindrome (a word that reads the same
backward as forward).
4. Vowel Counter
Take a sentence as input and count how many vowels (a, e, i, o, u) it contains.
5. Case Converter
7. Simple Calculator
9. String Reversal
Ask the user for their first name and last name:
● Combine the first three letters of the first name with the last three letters of the last
name.
● Print the suggested username.
● Check if the sentence starts with the given word or ends with the given word.
● Print the appropriate message.
● Replace all occurrences of the first word with the new word.
● Print the modified sentence.
Write a program to manage a library system where users can borrow books. The program
should:
1. Allow the user to input book titles to borrow (store in a list).
2. Display a summary showing the count of each borrowed book.
3. If no books are borrowed, display "No books borrowed."
2. Inventory Management
4. Polling System
Write a program for a simple polling system:
1. Allow users to vote for their favorite fruits from a predefined list (e.g., "Apple," "Banana,"
"Orange").
2. Store votes in a list.
3. At the end of polling, display the total votes for each fruit.
1. Starts with a dictionary of grocery items and their prices (e.g., {"Apple": 2.5,
"Banana": 1.2, "Orange": 1.8}).
2. Allows the user to input items to add to their cart.
3. Calculates the total price of all items in the cart.
4. If the cart is empty, display "Your cart is empty."
6. Expense Tracker
1. Allow the user to input categories and amounts (e.g., "Food 50", "Transport 30").
2. Store expenses in a dictionary where keys are categories and values are total amounts.
3. Display a summary of expenses for each category.
7. Gradebook Management
1. Allow the user to input student names and their scores.
2. Store this data in a dictionary, where names are keys and scores are values.
3. Display the average, highest, and lowest scores at the end.
8. Word Frequency Counter
9. Quiz Scorer