我试图让我的输入移动,当在只有空格或空白的行上按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."
您在
else
子句中再次调用了raw_input()
。而且,float(inp)
如果您不在任何地方分配它,它实际上不会做任何事情prepTotal.append(float(inp))
是您想要做的相关问题 更多 >
编程相关推荐