#๐ RPS Game
37 messages ยท Page 1 of 1 (latest)
@hearty parcel
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!
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!')```
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)
py goes on the same line as the backticks
which is on a different line as the code
```py
code
```
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.
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
Oh alright thank you
no need to wrap your values in parenthesis in those first few lines
How would I go about setting that up, I assume the same as I did with the "r" : "Rock" and so forth?
yes
Alright I edited it, so for int they do not need ()?
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
I think you can remove the whole thing if you replace random.randint with random.choice('rps')
thats true
Would def BOT_RPS(BOT_NUM):
return{1: "r", 2: "p", 3: "s"}
work?
thats overdesigned
Ahh let me try that
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
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)
That worked, thank you that is a lot better
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
So it should basically be used to recall things that may be used often?
I'm still slightly confused by def if I am going to be honest
I will try to, though I am going to have to do some thinking lol. Not sure how I am going to pull it off
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.