import random
options = ["rock", "paper", "scissors"]
user_wins = 0
computer_wins = 0
while True:
playerchoice = input('Choose Rock/Paper/Scissors/Quit ("Quit" is to quit the game)').lower()
if playerchoice == "quit":
quit
if playerchoice not in options:
continue
choice = random.randint(0, 2)
#0 rock 1 paper 2 scirscors
computerchoice = options[choice]
print(f"Computer picked {computerchoice}.")
if playerchoice == "rock" and computerchoice == "scissors":
print("You won!")
user_wins += 1
continue
elif playerchoice == "paper" and computerchoice == "rock":
print("You won!")
user_wins += 1
continue
elif playerchoice == "scissors" and computerchoice == "paper":
print("You won!")
user_wins += 1
continue
else:
print("You lose!")
computer_wins += 1
print(f"You won {user_wins} times.")
print(f"The computer won {computer_wins} times.")
if computer_wins > user_wins:
print("Computer Won!")
elif user_wins > computer_wins:
print("You win!")
else:
print("Wow! its a draw!")
print("Goodbye!")
#đź”’ why is the quit command not working
17 messages · Page 1 of 1 (latest)
@gray holly
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.
Closes after a period of inactivity, or when you send !close.
:warning: Your 3.12 eval job has completed with return code 0.
[No output]
In <3.13 quit requires one to use () to run it, 3.13 only changed stuff to make it work without ()
Also, it's a Quitter object with help stuff for repl. I'm more for using sys.exit directly instead of quit/exit
!d sys.exit
sys.exit([arg])```
Raise a [`SystemExit`](https://docs.python.org/3/library/exceptions.html#SystemExit) exception, signaling an intention to exit the interpreter.
!d quit
quit(code=None)``````py
exit(code=None)```
Objects that when printed, print a message like “Use quit() or Ctrl-D (i.e. EOF) to exit”, and when called, raise [`SystemExit`](https://docs.python.org/3/library/exceptions.html#SystemExit) with the specified exit code.
Similar names: pdbcommand.quit
That's how it looks on 3.12 (and lower)
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> quit()
~ $
Gotta use quit(), not quit
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.