小编Mr.*_*ous的帖子

为什么我的变量没有按定义显示?

我正在尝试将“摇滚,纸,剪刀”作为我的第二个程序。我一直遇到错误,

"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)

python python-3.x

-1
推荐指数
1
解决办法
38
查看次数

标签 统计

python ×1

python-3.x ×1