I need this program to do one of two things from my repeat function, but it should be able to do both and I can't work out why. It must do 2 things
I have tried making it just an if-else statement rather than if-elif-else, which didn't change anything, I have also tried rearranging the code, but that only changes the single output I can get from the subprogram. This is the subprogram currently:
def repeatloop():
repeat = input("Do you want to calculate another bill? (y/n): ")
if repeat == 'n' or 'N':
print("Goodbye.")
time.sleep(2)
sys.exit()
elif repeat == 'y' or 'Y':
main()
else:
print("Error. Program will shut down.")
time.sleep(2)
sys.exit()
It should be able to repeat the program (based on the y or Y input), terminate the program and display "Goodbye." based on the n or N input or it should display the "Error. Program will shut down." message before closing if an invalid input is entered. Many thanks to whoever can help me!
You may use in ()
for the comparison with a list. It compares the value of the variable with the list.
def repeatloop():
repeat = input("Do you want to calculate another bill? (y/n): ")
if repeat in ('n','N'):
print("Goodbye.")
time.sleep(2)
sys.exit()
elif repeat in ('y','Y'):
main()
else:
print("Error. Program will shut down.")
time.sleep(2)
sys.exit()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments