【发布时间】:2014-04-10 12:53:11
【问题描述】:
我正在尝试验证我的部分代码,如下所示:
loop2 =1
while loop2==1:
crntCurrency = input("Please enter the current currency: ")
if crntCurrency == 'Pound Sterling' or crntCurrency =='Euro' or crntCurrency =='US Dollar' or crntCurrency =='Japanese Yen':
break
else:
print("sorry that was invalid, please try agian:")
不过,我在这里又试了一次:
loop3 = 1
while loop3 ==1:
newCurrency = input("Please enter the currency you would like to convert to: ")
if newCurrency == 'Pound Sterling' or crntCurrency =='Euro' or crntCurrency =='US Dollar' or crntCurrency =='Japanese Yen':
break
else:
print("sorry that was invalid, please try agian:")
exRtFile = open ('exchangeRate.csv')
exchReader = csv.reader(exRtFile)
validateloop2 = 0
while validateloop2 == 0:
for row in exchReader:
currency = row and row[0]
if currency == newCurrency:
newRt = row[1]
validateloop2 =+1
toPound = crntAmnt/float(crntRt)
newAmount = int(toPound)*float(newRt)
print("You have: " ,newAmount, newCurrency,)
exRtFile.close()
在打印“抱歉无效,请重试:”之后,我陷入了一个永远循环。如果输入正确,我会收到错误消息(我认为这是一个缩进错误):
for row in exchReader:
ValueError: I/O operation on closed file.
【问题讨论】:
标签: python csv python-3.x