Exercise 3
Rock Paper Scissors Quest
Goal: Write a python code to play Rock Paper Scissors, user vs computer (cpu).
Part 1
- Fork and clone the following repository: https://github.com/ds-grundlagen/rps-quest
- Don't forget to use GitHub to commit and back up your changes to the code!
- In VS Code, write a python script called
rps.pythat does the following:- Write a function which ask the user's input. They may type: "rock", "paper", or "scissors". . You can call this function whatever you want.
- If the user inputs anything else besides these three options, show a warning message and exit the program with
exit()
- If the user inputs anything else besides these three options, show a warning message and exit the program with
- Write a function that randomly picks "rock", "paper", or "scissors", returning one of the three strings. You can call this function whatever you want.
- Now add a function a function called exactly:
decide_winner(user: str, cpu: str) → str- The input args
userandcpuare the choices of the user and computer, respectively. - The function must return one of three strings on behalf of the user:
"win","lose"or"draw" - This function contains the logic which calculates who wins
- The input args
- Now write the main logic flow of the game using the above functions.
- Print some message to inform the user what was picked and who won in the end.
- Write a function which ask the user's input. They may type: "rock", "paper", or "scissors". . You can call this function whatever you want.
- Try your script by running
uv run rps.py
Part 2
- Update your
rps.pyto also allow the user to typer,p, ors. - This should work in addition to still writing the whole word if the user wants
- Think about how to most simply implement this logic
Check
For this to work:
- Your script must be called exactly
rps.py - Your script must contain a function called exactly
decide_winner(user: str, cpu: str) → str - Your script must pick the cpu choice truly randomly
- The requirement outlined in Part 2 must work properly
Given these conditions, you should be able to successfully run the checking script:
```bash
uv run check_rps.py
```
Hopefully you now have the secret word for today!
Part 3: Bonus Project
This part is optional if you want some extra fun and an extra challenge!
- Duplicate your
rps.pyscript and come up with a new name for it: you're about to invent a new game! - Add your own new rule(s) to the classic version, whatever you can think of
- Edit your new script to work with your new rule
- Feel free to be creative with your rule and upgrade the original game as much or as little as you want
- Don't hesitate to ask us for help if you need ideas on how to implement your rule