gpt4 book ai didi

python - 运行 Python 程序时出现问题,错误 : Name 's' is not defined

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:52 27 4
gpt4 key购买 nike

<分区>

这是我的代码:

#This is a game to guess a random number.

import random

guessTaken = 0

print("Hello! What's your name kid")
myName = input()

number = random.randint(1,20)
print("Well, " + myName + ", I'm thinking of a number between 1 and 20.")

while guessTaken < 6:
print("Take a guess.")
guess = input()
guess = int(guess)

guessTaken = guessTaken + 1

if guess < number:
print("You guessed a little bit too low.")

if guess > number:
print("You guessed a little too high.")

if guess == number:
break

if guess == number:
guessTaken = str(guessTaken)
print("Well done " + myName + "! You guessed the number in " + guessTaken + " guesses!")

if guess != number:
number = str(number)
print("No dice kid. I was thinking of this number: " + number)

这是我得到的错误:

Name error: Name 's' is not defined.

我认为问题可能是我安装了 Python 3,但该程序正在由 Python 2.6 解释。如果可以帮助你们帮助我,我正在使用 Linux Mint。

使用Geany作为IDE,按F5进行测试。它可能默认加载 2.6,但我真的不知道。 :(

编辑:错误 1 ​​是:

File "GuessingGame.py", line 8, in <Module>
myName = input()

错误 2 是:

File <string>, line 1, in <Module>

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com