小编Clu*_*ter的帖子

Python:NameError名称'[input]'未定义

我正在尝试制作一个简单的小工具,用于将英寸转换为厘米,并且试图接受用户输入('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)

python undefined nameerror

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

标签 统计

nameerror ×1

python ×1

undefined ×1