Practice and reinforce the concepts from Lesson 5
:information_source: Before you start: Click this link and make a copy of the Colab Notebook to your Google Drive for coding.
Time estimate: 10 minutes
Create a program that determines the winner of a badminton game based on player scores.
Get player scores:
player1
and player2
Convert the inputs:
int()
to convert the string inputs to numbersCheck who wins using if-elif-else:
:bulb: Remember to use
int()
when getting input! Example:python
player1 = int(input("Enter Player 1 score: "))
Expected output if Player 1 wins:
Expected output if the game is draw:
Time estimate: 10 minutes
Build a number guessing game where users try to guess a number from a secret list.
Create the secret number list:
numbers = [3, 2, 6, 12, 9, 18]
Get the user's guess:
guess
int()
to convert the inputCheck if the guess is correct:
:bulb: To check if an item is in a list, use the
in
keyword:python
if guess in numbers: # The guess is correct!
Expected output if user's guess is correct:
Expected output if user's guess is wrong:
Time estimate: 15 minutes
Create a ticket pricing system for a museum based on visitor age.
Age | Category | Ticket Price |
---|---|---|
<= 12 | Children | RM 10 |
13-59 | Adult | RM 20 |
>= 60 | Senior Citizen | RM 15 |
Get visitor's age:
int()
Determine category and price:
Display the result:
Expected output for a 15 years old user:
Expected output:
What is your age? 15
Adult, RM 20
Time estimate: 20 minutes
Build a grading system that calculates total scores and assigns letter grades.
Total Score | Grade |
---|---|
>= 80 | A |
65-79 | B |
50-64 | C |
< 50 | F |
Get scores from user:
Calculate total score:
Determine the grade:
Display results:
:bulb: Tip Start checking from the highest grade (A) and work your way down. This makes your conditions simpler!
Assume the user's inputs are assignment: 18, midterm: 16, final exam: 55, the final output is:
Expected output:
Your total score is:89
You got A
"TypeError: '>' not supported"
int()
to convert inputs to numbersWrong output for edge cases
"NameError: name is not defined"
:warning: Warning
:emoji: Submission Instructions
Important: Review all your code and test with different inputs before submitting!
- Make sure your Colab notebook is saved
- Test each question with the example inputs
- Click the submission link below
- Follow the form instructions carefully
:link: Submit your exercise here
Submission deadline: Check with your instructor