当我不应该B时得到一个值错误

2024-10-04 11:35:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让我的输入移动,当在只有空格或空白的行上按enter键时,它不起作用,尽管它在给我正确的返回之前给了我一次值错误,这反过来似乎给我的数组附加了一个额外的值,并在整个程序上运行

import math

def getItems():
    quitNow = False
    while not quitNow:
        prepTotal = []
        paintTotal = []
        priceTotal1 = []
        priceTotal1d = []
        priceTotal2 = []
        priceTotal2d = []
        names = []
        loopQuit = False
        index = 1
        while not loopQuit:

            ans = raw_input("Enter a Name and press Enter to Continue\nEnter \"Q\" to Quit and get the Full Price: ")

            if(ans.lower() != "q"):
                innerLoopQuit = False
                names.append(ans)
                print "\nPlease enter your prep hours for " + names[index-1] + ": "
                while not innerLoopQuit:
                    try:
                        inp = raw_input()

                        if(inp == ""):
                            innerLoopQuit = True
                        else:
                            float(inp)
                            prepTotal.append(float(raw_input()))

                    except ValueError:
                        print "Please enter a valid number."

Tags: falseinputindexrawnamesnotenterinp