I'm a newbie in coding and Python in general and would like to know how to make my code loop itself when a user enters an invalid input. My code currently looks like this (and yes it is a simple calculator based on what I learned in the past few hours. Criticism is welcome):
from string import ascii_letters
class simplecalc:
print('This is only a simple calculator! Enter two numbers pls!')
num_1 = input('Enter no.1: ')
num_2 = input('Enter no.2: ')
operator = input('What operation do you want to do?: ')
if operator == '+':
calc_result = float(num_1) + float(num_2)
print(calc_result)
elif operator == '-':
calc_result = float(num_1) - float(num_2)
print(calc_result)
elif operator == '/':
calc_result = float(num_1) / float(num_2)
print(calc_result)
elif operator == '*':
calc_result = float(num_1) * float(num_2)
print(calc_result)
else:
print('WrongInput')
Thanks for those who will answer!