currency_input = input('Enter GBP values (separated by whitespace): ')
currency_list = currency_input.split()
# arrays to store currencies and converted currencies
GBPvalues = []
convertedEuros = []
convertedDollars = []
convertedYen = []
convertedRupee = []
# stores GBP values in array GBPvalues
for x in currency_list:
GBPvalues.append(int(x))
# function for converting GBP to euros
def euroConversion():
for x in GBPvalues:
euros = x * 114 / 100
for e in euros:
convertedEuros.append(euros)
# function for converting GBP to dollars
def dollarConversion():
for x in GBPvalues:
dollars = x * 134 / 100
for d in dollars:
convertedDollars.append(float(dollars))
# functions for converting GBP to yen
def yenConversion():
for x in GBPvalues:
yen = x * 15074 / 100
for y in yen:
convertedYen.append(float(dollars))
# functions for converting GBP to rupee
def rupeeConversion():
for x in GBPvalues:
rupee = x * 8614 / 100
for r in rupee:
convertedRupee.append(float(rupee))
# function to output the currency and converted currency
def conversionOutput():
print('1. Euros')
print('2. Dollars')
print('3. Yen')
print('4. Rupees')
print('5. Exit')
userInput = input()
if userInput == '1':
euroConversion()
for i in range(10):
print(GBPvalues[i] + convertedEuros[i])
# adds up total of GBP and euros
totalGBP = sum(GBPvalues)
totalEuros = sum(convertedEuros)
print(totalGBP)
print(totalEuros)
if userInput == '2':
dollarConversion()
for i in range(10):
print(GBPvalues[i] + convertedDollars[i])
# adds up total of GBP and dollars
totalGBP = sum(GBPvalues)
totalDollars = sum(convertedDollars)
print(totalGBP)
print(totalDollars)
if userInput == '3':
yenConversion()
for i in range(10):
print(GBPvalues[i] + convertedYen[i])
# adds up total of GBP and yen
totalGBP = sum(GBPvalues)
totalYen = sum(convertedYen)
print(totalGBP)
print(totalYen)
if userInput == '4':
rupeeConversion()
for i in range(10):
print(GBPvalues[i] + convertedRupee[i])
# adds up total of GBP rupee
totalGBP = sum(GBPvalues)
totalRupee = sum(convertedRupee)
print(totalGBP)
print(convertedRupee)
if userInput == '5':
System.exit()
conversionOutput()
所以我有一个货币转换器的代码,我正在尝试创建。我已经为此奋斗了一段时间,现在有几个不同的错误,其中大部分已经被整理出来,除了当我现在运行这个程序,我得到的错误:
'float' object is not iterable on the line 'for e in euros:', 'for d in dollars', for y in yen' and 'for r in rupee'.
我知道是什么导致了这个错误,我只是不知道我需要改变什么才能使这个程序完美地运行。这方面的任何帮助都会非常有用。你知道吗
因为
euros
是一个数字,而不是一个列表,我想你可以把英镑兑换成欧元:相关问题 更多 >
编程相关推荐