while True: reply = input('Enter text:') if reply == 'stop' : break try: num = int(reply) #尝试的语句 except: print('Bad!' * 8) #失败则执行 else: print(int(reply) ** 2) #成功则执行print('Bye')
本文共 239 字,大约阅读时间需要 1 分钟。
while True: reply = input('Enter text:') if reply == 'stop' : break try: num = int(reply) #尝试的语句 except: print('Bad!' * 8) #失败则执行 else: print(int(reply) ** 2) #成功则执行print('Bye')
转载于:https://my.oschina.net/funs/blog/169528