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.py that does the following:
    1. 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()
    2. Write a function that randomly picks "rock", "paper", or "scissors", returning one of the three strings. You can call this function whatever you want.
    3. Now add a function a function called exactly: decide_winner(user: str, cpu: str) → str
      • The input args user and cpu are 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
    4. Now write the main logic flow of the game using the above functions.
    5. Print some message to inform the user what was picked and who won in the end.
  • Try your script by running uv run rps.py

Part 2

  • Update your rps.py to also allow the user to type r, p , or s .
  • 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:

  1. Your script must be called exactly rps.py
  2. Your script must contain a function called exactly decide_winner(user: str, cpu: str) → str
  3. Your script must pick the cpu choice truly randomly
  4. 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!

  1. Duplicate your rps.py script and come up with a new name for it: you're about to invent a new game!
  2. Add your own new rule(s) to the classic version, whatever you can think of
  3. Edit your new script to work with your new rule
  4. Feel free to be creative with your rule and upgrade the original game as much or as little as you want
  5. Don't hesitate to ask us for help if you need ideas on how to implement your rule

Submit the answer: