我正在尝试将“摇滚,纸,剪刀”作为我的第二个程序。我一直遇到错误,
"Traceback (most recent call last):
File "/home/cabox/workspace/main.py", line 118, in <module>
File "/home/cabox/workspace/main.py", line 48, in Rock_Paper_Scissors
else:
NameError: name 'rps_choice' is not defined"
Run Code Online (Sandbox Code Playgroud)
这是代码。
import time
import random
def Rock_Paper_Scissors():
print("Welcome to the \"Rock, Paper, Scissors\" game!")
time.sleep(2)
def rps_input():
while True:
rps_choice = input("Say \"Rock\", \"Paper\", or \"Scissors\" to get started: ")
if rps_choice.upper() == "ROCK":
print("Great! You chose", rps_choice.upper(), end='')
print("! The computer picked...")
return rps_choice.upper()
if rps_choice.upper() == "PAPER":
print("Great! You chose", rps_choice.upper(), end='')
print("! …Run Code Online (Sandbox Code Playgroud)