Skip to content Skip to sidebar Skip to footer

How To Use Sys.exit() If Input Is Equal To Specific Number

I am looking to correct this code so that when the user inputs 99999 then the code stops running, im also looking to make it so that if the user input is 999 it sets the total to 0

Solution 1:

So you're taking the input as a string and immediately converting it to an int, but you could actually convert it to an int later and check for some words in your input first.

Right now you have

pay_this_week = int(input("..."))

but if you change this to

input_from_user = input("...")
pay_this_week = int(input_from_user)

then we can add some more code inbetween

input_from_user = input("...")
if input_from_user == "done":
    return# this will exit the function and so end executionelif input_from_user == "reset":
    total = 0# reset the totalelse:
    pay_this_week = int(input_from_user)

this should have the desired effect

Post a Comment for "How To Use Sys.exit() If Input Is Equal To Specific Number"