#๐Ÿ”’ RPS Game

37 messages ยท Page 1 of 1 (latest)

hearty parcel
#

Is there anything I should do differently? I am just looking to learn more skills in Python, and this was just a silly project.

wooden iglooBOT
#

@hearty parcel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @hearty parcel!

Please edit your message to use a code block

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
hearty parcel
#
import random
BOT_SCORE = (0)
USER_SCORE = (0)
TIE = (0)
ROUNDS = (0)

def full_word(letter):
      return {"r": "Rock", "p": "Paper", "s": "Scissors"}[letter]

print("Rock, Paper, Scissors\nBy: JayTDK\n")

while True:
    USER_RPS = input("Rock, paper, or scissors? (r, p, s): ")
    if USER_RPS not in ["r", "p", "s"]:
        print("Invalid Value\n")
        continue

    BOT_NUM = random.randint(1,3)

    BOT_RPS = ""
    if BOT_NUM == 1:
     BOT_RPS = "r"
    elif BOT_NUM == 2:
        BOT_RPS = "p"
    elif BOT_NUM == 3:
        BOT_RPS = "s"
    else:
        print("BOT ERROR")

    print(f"You chose {full_word(USER_RPS)} and the bot chose {full_word(BOT_RPS)}")


    if USER_RPS == BOT_RPS:
        print("Tie\n")
        TIE += 1
    elif (USER_RPS == "r" and BOT_RPS == "s") or (USER_RPS == "p" and BOT_RPS == "r") or (USER_RPS == "s" and BOT_RPS == "p"):
      print("You win!\n")
      USER_SCORE += 1
    else:
      print("Bot wins!\n")
      BOT_SCORE += 1
    ROUNDS += 1

    print(f"Over {ROUNDS} rounds\nYour score is {USER_SCORE}\nThe Bots score is {BOT_SCORE}\nYou have tied {TIE} times.\n")
    print("-" * 40)
hardy bane
#

py goes on the same line as the backticks

#

which is on a different line as the code

#

```py
code
```

hearty parcel
#

Hmm I did that

#

I might be struggling lol

sturdy pawn
# hearty parcel ```py import random BOT_SCORE = (0) USER_SCORE = (0) TIE = (0) ROUNDS = (0) de...

It looks like a correct implementation of the game at a glance.
Personally I would define a dictionary instead of the whole if BOT_NUM == 1: block. I would try to implement the rules a bit more separately to the game, e.g. defining Rock, Paper Scissors as a set of objects, with a total ordering defined on them (__le__(self) and @functools.total_ordering). Also maybe there are more interesting tactics to explore for the BOT than randomly picking a value. Overall great job.

hardy bane
#
import random
BOT_SCORE = (0)
USER_SCORE = (0)
TIE = (0)
ROUNDS = (0)

def full_word(letter):
      return {"r": "Rock", "p": "Paper", "s": "Scissors"}[letter]

print("Rock, Paper, Scissors\nBy: JayTDK\n")

while True:
    USER_RPS = input("Rock, paper, or scissors? (r, p, s): ")
    if USER_RPS not in ["r", "p", "s"]:
        print("Invalid Value\n")
        continue

    BOT_NUM = random.randint(1,3)

    BOT_RPS = ""
    if BOT_NUM == 1:
     BOT_RPS = "r"
    elif BOT_NUM == 2:
        BOT_RPS = "p"
    elif BOT_NUM == 3:
        BOT_RPS = "s"
    else:
        print("BOT ERROR")

    print(f"You chose {full_word(USER_RPS)} and the bot chose {full_word(BOT_RPS)}")


    if USER_RPS == BOT_RPS:
        print("Tie\n")
        TIE += 1
    elif (USER_RPS == "r" and BOT_RPS == "s") or (USER_RPS == "p" and BOT_RPS == "r") or (USER_RPS == "s" and BOT_RPS == "p"):
      print("You win!\n")
      USER_SCORE += 1
    else:
      print("Bot wins!\n")
      BOT_SCORE += 1
    ROUNDS += 1

    print(f"Over {ROUNDS} rounds\nYour score is {USER_SCORE}\nThe Bots score is {BOT_SCORE}\nYou have tied {TIE} times.\n")
    print("-" * 40)
#

looks like theres a space at the start of the import random line

#

i removed it and it worked

hearty parcel
#

Oh alright thank you

hardy bane
#

no need to wrap your values in parenthesis in those first few lines

hearty parcel
hardy bane
#

yes

hearty parcel
hardy bane
#

nope

#

parenthesis are mostly for calling functions and order of operations

#

sometimes they are good for visual clarity like in your elif where the condition is really long

sturdy pawn
hardy bane
#

thats true

hearty parcel
#

Would def BOT_RPS(BOT_NUM):
return{1: "r", 2: "p", 3: "s"}
work?

hardy bane
#

thats overdesigned

hardy bane
#

no need

#

if i were to recommend a step up from this, try making tic-tac-toe next.

#

will be noticeably harder but you can do it

hearty parcel
#
import random
BOT_SCORE = 0
USER_SCORE = 0
TIE = 0
ROUNDS = 0

def full_word(letter):
      return {"r": "Rock", "p": "Paper", "s": "Scissors"}[letter]

print("Rock, Paper, Scissors\nBy: JayTDK\n")

while True:
    USER_RPS = input("Rock, paper, or scissors? (r, p, s): ")
    if USER_RPS not in ["r", "p", "s"]:
        print("Invalid Value\n")
        continue

    BOT_RPS = random.choice("rps")

    '''BOT_RPS = ""
    if BOT_NUM == 1:
     BOT_RPS = "r"
    elif BOT_NUM == 2:
        BOT_RPS = "p"
    elif BOT_NUM == 3:
        BOT_RPS = "s"
    else:
        print("BOT ERROR")'''

    print(f"You chose {full_word(USER_RPS)} and the bot chose {full_word(BOT_RPS)}")


    if USER_RPS == BOT_RPS:
        print("Tie\n")
        TIE += 1
    elif (USER_RPS == "r" and BOT_RPS == "s") or (USER_RPS == "p" and BOT_RPS == "r") or (USER_RPS == "s" and BOT_RPS == "p"):
      print("You win!\n")
      USER_SCORE += 1
    else:
      print("Bot wins!\n")
      BOT_SCORE += 1
    ROUNDS += 1

    print(f"Over {ROUNDS} rounds\nYour score is {USER_SCORE}\nThe Bots score is {BOT_SCORE}\nYou have tied {TIE} times.\n")
    print("-" * 40)
hearty parcel
hardy bane
# hearty parcel Would def BOT_RPS(BOT_NUM): return{1: "r", 2: "p", 3: "s"} work?

a function to get a single value a single time is kind of pointless. your functions should be something like "i want to solve problems in this shape, but maybe not exactly the same every time."

e.g. a function square that takes a number and returns that number squared. its different every time depending on what you call it with, but the process is the same no matter what you call it with

hearty parcel
#

I'm still slightly confused by def if I am going to be honest

hearty parcel
wooden iglooBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.