我尝试运行这个简单的python脚本时收到错误:
input_variable = input ("Enter your name: ")
print ("your name is" + input_variable)
Run Code Online (Sandbox Code Playgroud)
让我说我输入"dude",我得到的错误是:
line 1, in <module>
input_variable = input ("Enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'dude' is not defined
Run Code Online (Sandbox Code Playgroud)
我正在运行Mac OS X 10.9.1,我正在使用安装python 3.3附带的Python Launcher应用程序来运行脚本.
编辑:我意识到我用2.7运行这些脚本.我想真正的问题是我如何使用3.3版运行我的脚本?我想如果我将我的脚本拖放到我的应用程序文件夹中的Python 3.3文件夹内的Python Launcher应用程序之上,它将使用3.3启动我的脚本.我想这个方法仍然用2.7启动脚本.那么我如何使用3.3?
我正在学习python并且有这个错误.我可以弄清楚代码中的错误是什么.
File "<string>", line 1, in <module>.
Name = ""
Desc = ""
Gender = ""
Race = ""
# Prompt user for user-defined information
Name = input('What is your Name? ')
Desc = input('Describe yourself: ')
Run Code Online (Sandbox Code Playgroud)
当我运行该程序
它输出你的名字是什么?(我输入d)
这给出了错误
Traceback (most recent call last):
File "/python/chargen.py", line 19, in <module>
Name = input('What is your Name? ')
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
Run Code Online (Sandbox Code Playgroud)
这是Python 3 for Absolute Beginners的示例代码.
我正在尝试制作一个简单的小工具,用于将英寸转换为厘米,并且试图接受用户输入('y'或'n')以决定是否进行另一次转换或终止.这就是我所做的:
import time
def intro():
print "Welcome! This program will convert inches to centimeters for you.\n"
convert()
def convert():
input_cm = input(("Inches: "))
inches_conv = input_cm * 2.54
print "Centimeters: %f\n" % inches_conv
time.sleep(3)
restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
if restart == 'y':
convert()
elif restart == 'n':
end_fast()
else:
print "I didn't quite understand that answer. Terminating."
end_slow()
def end_fast():
print "This program will close in 5 seconds."
time.sleep(5)
def end_slow(): …Run Code Online (Sandbox Code Playgroud) 我可以用一些帮助搞清楚为什么我的游戏不允许我拿起一把剑.出现的错误消息是
回溯(最近一次调用最后一次):文件"",第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)