相关疑难解决方法(0)

名称未定义错误

我很清楚这是一个noob问题,但我似乎无法找到解决方案,我对编程很新,但渴望学习.我正在浏览python中的第一个google clases,这是我得到的错误.

def both_ends(s):
  print s[0:2], s[3:5]
  return

x = input('...: ')
both_ends(x)

sergei@sergei-MS-7253:~/Desktop/p2$ python test2.py
...: haloj
Traceback (most recent call last):
  File "test2.py", line 10, in <module>
    x = input('...: ')
  File "<string>", line 1, in <module>
NameError: name 'haloj' is not defined
Run Code Online (Sandbox Code Playgroud)

请解释一下问题所在.

谢谢

python string

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

NameError:未定义名称"April"

我知道这是愚蠢的,但我无法弄清楚为什么它不起作用.请帮忙.

def main():
    yourAge=getAge() #get subject's age
    yourWeight=getWeight() #get subject's weight 
    yourBirthMonth=getMonth() #get subject's birth month
    correctAnswers(getAge, getWeight, getMonth)

def getAge():
    yourAge=input('Enter your age. ')
    return yourAge

def getWeight():
    yourWeight=input('Enter your weight.')
    return yourWeight

def getMonth():
    yourBirthMonth=input('Enter your birth month. ')
    return yourBirthMonth

def correctAnswers(getAge, getWeight, getMonth):
    if getAge <= 25:
        print'Congratulations, age is less than 25.'

    if getWeight >= 128:
        print'Congratulations, weight is more than 128.'

    if getMonth == 'April':
        print'Congratulations, month is April.'

main()
Run Code Online (Sandbox Code Playgroud)

追溯:

 Traceback (most recent …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
1111
查看次数

python说变量名是语法错误

每当我尝试在python中运行前两行时,它会说:

SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

并突出显示我想要定义的变量的名称(Yname).

这些是我正在尝试运行的行:

print("Hello what's your name?")\       
Yname = input("your name:")
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
277
查看次数

基于Python文本的冒险游戏,需要帮助

我可以用一些帮助搞清楚为什么我的游戏不允许我拿起一把剑.出现的错误消息是

回溯(最近一次调用最后一次):文件"",第36行,在文件"",第1行,在NameError中:名称'y'未定义

这是基本游戏,我对此非常新,所以简单的术语会很好.

print 'You enter a Dungeon with three doors. Do you want to enter door #1 door #2 or door #3?'
door = raw_input('> ')

if door == "1":
    print 'Theres a dragon eating a human, the dragon is massive and looks terrifying'
    print 'what do you want to do?'
    print '#1 try to save the human'
    print '#2 scream and run around'
    dragon = raw_input('> ')

    if dragon == "1":
        print 'You approach the dragon sneakily. After …
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
201
查看次数

标签 统计

python ×4

string ×1