I wrote this simple calculator program to ask for two numbers and then perform a certain action on them like dividing the first by the second etc. I implemented it in a big while loop that is repeated if the user chooses to repeat it after a calculation. However, after the user enters the operation they want to perform the program does not give the answer but asks the user if they want to repeat. What did I do wrong?
import random, time
valid_operations = ("/", "*", "+", "-")
valid = 3
repeat = "y"
while repeat == "y":
number_1 = input('Enter first number \n')
if number_1.isdigit() == True:
num_1 = number_1
else:
print("that is not a valid integer")
exit()
number_2 = input('Enter second number \n')
if number_2.isdigit() == True:
num_2 = number_2
else:
print("that is not a valid integer")
exit()
operation = input("what operation would you like? \nvalid operations include:\n/ - divide\n* - multiply\n+ - add\n- - subtract\n")
while valid > 0:
if operation in valid_operations:
if operation == "/":
print(f"Answer = {int(num_1) / int(num_2)}")
valid -= 3
elif operation == "*":
print(f"Answer = {int(num_1) * int(num_2)}")
valid -= 3
elif operation == "+":
print(f"Answer = {int(num_1) + int(num_2)}")
valid -= 3
elif operation == "-":
print(f"Answer = {int(num_1) - int(num_2)}")
valid -= 3
else:
print(f"that is not a valid operation you have {valid} more attmepts to type a valid operation")
valid -= 1
time.sleep(2)
want_rep = input("would you like to do another calculation? y/n\n")
if want_rep == "y":
repeat = "y"
elif want_rep == "n":
repeat = "n"
else:
print("that is not a valid response, please choose either yes - y or no - n")
exit()