I spent 3+ hours, trying to make it work, but I failed so far. I couldn't make a while loop run for the operators. I added a while loop for the operator, but then it only returns to the second while loop which asks me to input the first and second number again while I already inputted the correct first and second number. I hope my question makes sense. Thanks very much!
# a better way
#stackOverFlow Reference Page:
# https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response
print("My first p calculator")
print("+ for Addition")
print("- for subtraction")
print("* for Multiplication")
print("/ for Division")
print("% for remainder")
while True:
result = 0
while True:
try:
first_num = float(input("Enter first number:"))
except ValueError:
print("Sorry, enter a number:")
continue
else:
break
while True:
try:
second_number = float(input("Enter 2nd number: "))
except ValueError:
print("Sorry, enter a number: ")
continue
else:
break
# How to create a while loop for the below operator to
# ask to input the correct operator, if I keep inputting wrong operators.
# Thanks Very Much!
operation = input("Enter Operator: ")
if operation == "+":
result = first_num + second_number
elif operation == "-":
result = first_num - second_number
elif operation == "*":
result = first_num * second_number
elif operation == "/":
result = first_num / second_number
elif operation == "%":
result = first_num % second_number
# This will RUN, but when operator is inputted WRONG, it will go back
# to ask me to enter first number and second number.(the 2nd While Loop I guess).
# I want it to ask for the input of Operator Again and Again UnTil the input is the correct operator.
# NOT go back to ask first number and second number.
# I tried to create the third while loop for the operators
# but I couldn't get it to run. only when back to 2nd while Loop.
#I thought it was indentation error, but I tried, still couldn't get it to work.
print(result)