Introduction to Python - Weekly Challenge 1
Week 1: Weekly Challenges
Task 1: Simple Calculator
Main Goals:
- Create a calculator that can perform basic arithmetic operations.
- Implement functions for each operation.
- Use a loop to allow multiple calculations.
Guidelines:
- Create functions for addition, subtraction, multiplication, and division.
- Use a while loop to keep the calculator running until the user chooses to exit.
- Implement input validation to ensure valid numbers and operators are entered.
- Handle division by zero errors (try using if and else).
Task 2: Number Guessing Game
Main Goals:
- Create a game where the computer generates a random number and the user tries to guess it.
- Implement input validation and provide feedback to the user.
- Use loops to allow multiple guesses.
Guidelines:
- Use the random module to generate a number between 1 and 100.
- Use a while loop to allow the user to keep guessing until they get the correct number.
- Implement input validation to ensure the user enters a valid number.
- Provide feedback after each guess (too high, too low, or correct).
- Keep track of the number of guesses and display it when the user guesses correctly.
Task 3: A tip calculator
Main Goals:
- Create a program that calculates the tip amount and total bill based on user input.
- Practice working with user input, variables, and basic arithmetic operations.
- Implement input validation to ensure proper data entry.
- Use functions to organize code and improve readability.
- Format output to display currency values correctly.
Guidelines:
- Define constant of default tip percentage (set to 15%).
- Create a function to get valid numeric input from the user.
- Create a function to calculate the tip amount and total bill.
- Use a while loop to keep asking for input until a valid number is entered (input validation), with the exception of ‘q’ to exit the program.
- Use f-strings to format the output, displaying currency values with two decimal places.
Task 4: Mad Libs Generator
Main Goals:
- Create a program that generates a story by asking the user for various words.
- Use string formatting to insert the user’s words into a pre-written story.
- Implement functions to make the code more organized.
Guidelines:
- Create a function to get user input for different types of words (nouns, verbs, adjectives, etc.).
- Store the story template as a multi-line string.
- Use f-strings or the format() method to insert the user’s words into the story.
- Implement error handling for unexpected inputs.
- Allow the user to generate multiple stories or exit the program.
Note: All the tasks need to be in separate .py
files. You can send them to me by email, through DM on Discord or by sending me the link to your GitHub repository with the task files. If you are using Google Colab (only for this week), you can share the link to your Colab notebook with me, but allow me to be a commenter. The notebook should have the title Week1
.
This post is licensed under CC BY 4.0 by the author.