Looking to validate that the user is indeed inputting an int and not a string for the values and also looking to make sure they are using one of the operation symbols for the opeeration and not anything else. If they do enter otherwise, want to be able to display an error and loop to the beginning of the question and start over.
def redo():
retry=input("would you like to start over? \n enter 'y' for yes or 'n' for no")
if retry=='y':
solve()
elif retry=='n':
print("thanks for playing!")
def solve():
a=int(input("Enter the first value: "))
b=int(input("enter the second value: "))
op=input('Enter the operation, \n you may enter either a +, -, *, %, or a ^: ')
if op=='+':
print(f'the value of {a} plus {b} is : {add(a,b)}')
elif op=='-':
print(f'the value of {a} minus {b} is : {sub(a,b)}')
elif op == '*':
print(f'the value of {a} multiplied to {b} is : {mult(a,b)}')
elif op=='/':
print(f'the value of {a} to the divided by {b} is : {div(a,b)}')
elif op =='^':
print(f'the value of {a} to the power of {b} is : {exp(a,b)}')
else:
print('your operation could not be understood, please choose from the list ')
redo()
def add(a,b):
return int(a) +int(b)
def sub(a,b):
return int(a) - int(b)
def mult(a,b):
return int(a) *int(b)
def div(a,b):
return int(a)/int(b)
def exp(a,b):
return int(a) ** int(b)
solve()