函数 break 和 pass 似乎无法在正确的输入下工作,程序停止,如果没有正确的输入,程序决定不中断而是打印字符串,告诉用户存在问题并继续运行。
currency = str(raw_input ("""what currency would you like to covert: GBP, EURO, USD OR YEN?
"""))
exchange = str(raw_input("""what currency would you like in exchange? : GBP, EURO, USD OR YEN?
"""))
amount = int(input("""how much would you like to convert?
"""))
valid_input = ('EUR','eur','GBP','gbp' ,'USD','usd','JPY','jpy')
while True:
if currency in valid_input and exchange in valid_input:
pass
else:
print("incorrect input, please restart program")
break
decision = str(raw_input("""Please enter u for user input exchange rate or s for the preset exchange rate
"""))
if decision == "u" :
user_rate = raw_input("Please enter the current exchange rate")
exchange_value = int(amount) * int(user_rate)
print ("At the user found exchange rate you will receive",exchange_value,exchange)
elif decision == "s" :
if currency == "GBP" and exchange == "USD":
exchange_value= int(amount) * 1.6048
print ("At the preset exchange rate you will receive",exchange_value,exchange)
if currency == "GBP" and exchange == "EUR":
exchange_value= int(amount) * 1.2399
print ("At the preset exchange rate you will receive",exchange_value,exchange)