为了账号安全,请及时绑定邮箱和手机立即绑定

中断和传递功能未正确处理

中断和传递功能未正确处理

海绵宝宝撒 2021-03-18 14:15:00
函数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")        breakdecision = 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)
查看完整描述

2 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

“中断”仅在insinde开关中有效,并且持续/


查看完整回答
反对 回复 2021-03-23
  • 2 回答
  • 0 关注
  • 158 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信