python - how do i safeguard my program from another exception while handling the same one? -
try: grosscheck = int(input("how much? (figures pls.)\n")) except valueerror: grosscheck = int(input("how much? (figures pls.)\n")) tenpees = grosscheck * 0.1 realpees = grosscheck - tenpees print("you've got " + str(realpees))
i got:
valueerror: invalid literal int() base 10: 'w' during handling of above exception, exception occurred:
the thing handled same exception. i'm trying handle in case user still enters wrong value(s) multiple times without breaking program.
you need somehow handle exception. 1 way keep asking:
try: grosscheck = int(input("how much? (figures pls.)\n")) except valueerror: while true: try: grosscheck = int(input("how much? (figures pls.)\n")) break except valueerror: pass
Comments
Post a Comment