我已经在这里呆了几个小时,搜索问题,甚至问我的哥哥,他是一个大四的EE,甚至他都被难住了。这是为一个项目,今晚午夜前到期,我似乎无法摆脱这个错误。有人能看看我的代码并找出为什么我总是出现这个错误吗?谢谢,是的,它们在while语句下面正确地缩进。在
# Initialize Variables
count = 0
#First Customer Input
cus = input("Enter customer's name: ")
custype = input("Enter customer's service type (R for Residential. B for Business): ")
location = input("Enter customer's service location (C for City. P for Parish): ")
kwh = eval(input("Enter customer's number of Kilowatt Hours Used: ")
#Repeat loop based on input items NOT being the sentinel value
while (count < 10):
if custype == 'R' and location1 == 'C':
rate = residentialCity
elif custype == 'R' and location1 == 'P':
rate = residentialParish
elif custype == 'B' and location1 == 'C' or 'P':
rate = business
正如上面的答案所说,你缺少一个括号:
为什么需要
^{pr2}$eval
语句?似乎您需要一个数字,并希望将字符串更改为整数。为什么不这样做呢?在只是一个建议,但是除非没有更好的方法,否则不要使用
eval
。它是不安全和不稳定的,有人可能不小心,或没有,输入一个代码和混乱您的程序。在数圆括号。在
正如D.Shawley在一篇评论中指出的,将用户输入传递给
eval
可能会造成任意的坏事。你为什么要在那里使用eval
?在相关问题 更多 >
编程相关推荐