在python中如何通过浮点数将列表中的变量分开?

时间:2014-10-29 16:12:13

标签: python-3.x

将欧元兑换成英镑并显示在表格中的代码

def exchangeTable():

    for i in range [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]:
        exchangeRate = 1.15
        pounds = i//exchangeRate
        print(i,pounds)

2 个答案:

答案 0 :(得分:0)

也许这就是你想要的代码:

def exchangeTable(euro_range):
    if euro_range < 0:
        raise Exception('Received negative range: {0}'.format(euro_range))
    if euro_range == 0:
        print('0 euros = 0 pounds')
        return
    exchange_rate = 1.15
    pounds = 1 / exchange_rate
    print ('1 euro = {0} pound'.format(pounds))
    if euro_range > 1:
        for i in range(2, euro_range + 1):
            pounds = i / exchange_rate
            print('{0} euros = {1} pounds'.format(i, pounds))

答案 1 :(得分:0)

我已经完成了这些人感谢你们的帮助所有人的回答:

def exchangeTable():

for i in range (0,21):
    exchangeRate = 1.15
    pounds = i/exchangeRate
    print(i,"euros = ","{0:0.2f} pounds".format(pounds))