0
currencies = {'yen': 0.0067, 'bsp': 1.35, 'usd': 0.65, 'ero': 0.85}

if choice == "2":
    Current_Currency = input("What currency do you want to exchange: Japenese Yen if so please type yen // British Sterling Pound please type bsp // US Dollers please Type usd // Euro please type ero.")
    amount = input("Type amount you wish to exchange")
    Future_Currency = input("What currency do you want to exchange into: Japenese Yen if so please type yen // British Sterling Pound please type bsp // US Dollers please Type usd // Euro please type ero.")
    New_Amount = Future_Currency / Current_Currency * amount

老实说,这让我很生气,我只需要解决我无法克服的最后一个障碍我是一个非常大的新手,所以请保持语言简单

4

1 回答 1

2

Future_Currency 和 Current_Currency 都是字符串,作为输入。看起来您想要将它们用作费率字典的键,如下所示:

New_Amount = currencies[Future_Currency] / currencies[Current_Currency] * amount

或者,为了便于阅读,分成更多行:

Future_Value = currencies[Future_Currency]
Current_Value = currencies[Current_Currency]
ratio = Future_Value / Current_Value
New_Amount = ratio * amount
于 2013-08-15T21:20:41.283 回答