#๐Ÿ”’ rock paper scissors game

13 messages ยท Page 1 of 1 (latest)

exotic bobcat
rustic onyxBOT
#

@exotic bobcat

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.

worn cape
#

put the code in a while True loop

exotic bobcat
#

it is in a while true loop

#

but if i dont break it will just print tie game or you lose infinitely

#

i want it to replay the game instead

boreal moat
#

your while loop makes no sense

#

you break out of the loop in every case

torpid prawn
#

You need to put the entire game in a while loop

#
import random

options = ["rock", "paper", "scissors"]

while True:
    user_pick = None
    while user_pick not in options:
        user_pick = input("Enter pick (rock, paper, scissors): ")
        
    computer_pick = random.choice(options)

    print(f"You chose {user_pick}, computer chose {computer_pick}")

    if user_pick == computer_pick:
        print(f"Both players chose {user_pick}. Tie game.")  
    elif (user_pick == "rock" and computer_pick == "scissors") or (user_pick == "scissors" and computer_pick == "paper") or (user_pick == "paper" and computer_pick == "rock"):
        print("You win. Congratulations")
    else:
        print("You lose. Try again.")
        
    try_again = input("Play again? (y/n): ")
    if try_again == "n":
        break
exotic bobcat
#

i see thank you

rustic onyxBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.