我在2.7有一个工作货币转换器,但我想确保程序不会获取它无法处理的用户输入的数据。如何使用break语句
- 如何获取用户输入要理解不相关的情况下
- 如何让程序重新启动,如果用户输入错误的;即如果中断,但我不知道如何做到这一点,尽管四处搜索并测试了一些方法。
我已经留下了其余的代码,因为它是微不足道的,有效地使用预设数字复制第一组乘法。
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?
"""))
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)
有没有循环。你不能从非循环中突破。 – Makoto 2013-05-11 16:21:48
无关:'str(raw_input(...))'是多余的,因为'raw_input'返回一个字符串。 'int(input())'应该是'int(raw_input())'。 – bereal 2013-05-11 17:31:00