+ 2

i want if user enters Y the prog should rerun else terminate.

while (True): func = input("enter one of the function out of \n +\n -\n *\n") if func == "+": num1 = int(input("number 1:\n")) num2 = int(input("number 2:\n")) print(num1 + num2) elif func == "-": num1 = int(input("number 1:\n")) num2 = int(input("number 2:\n")) print(num1 - num2) elif func == "*": num1 = int(input("number 1:\n")) num2 = int(input("number 2:\n")) print(num1 * num2) else: print("enter one of the option") endr = input("do you want to run again\n Y OR N\n") if endr == "N" or "n": print("bye\n") elif endr == "Y" or "y": print("ok\n")

28th Oct 2021, 9:56 AM
Abhishek
Abhishek - avatar
1 Antwort
+ 6
Check whether <endr> was `in` "Nn" if endr in "Nn": print("bye\n") break # break out of loop else: print("ok\n")
28th Oct 2021, 10:13 AM
Ipang