Skip to content
← Back to Community
HELP PLEASE : how do I use the return function?
Profile icon
ElvisNguyen

can someone please help me out. How do i return it back to " A = int(input("Please Enter A Numerical Length For the Triangle: A = "))" . I have no clues on how to do it. Could some expert help me out please!!

Answered by ash15khng [earned 5 cycles]
View Answer
Voters
Profile icon
ElvisNguyen
Comments
hotnewtop
Profile icon
ash15khng

You could use a while True loop in front of the try except clause, then add a break in the try part.

while True: try: # asking the user to input the length of side A and print it out A = int(input("Please Enter A Numerical Length For the Triangle: A = ")) break except ValueError:# if the input is none numerical, let the user know and ask the user to enter a numberical print("That is not an Numerical, Please ONLY ENTER NUMERICAL")
Profile icon
RyanRana

I did it using the strip of code.

name = input("What is your name? \n") #asking the user their name
print("Welcome, " + name + "!") #print the message with customer name
print("Let plays the triangle guesing game") #welcome messages
is_number = False
while is_number == False:
A = input("Please Enter A Numerical Length For the Triangle: A = ")

for i in A:
if i in ["0","1","2","3","4","5","6","7","8","9"]:
is_number = True

else: print("That is not an Numerical, Please ONLY ENTER NUMERICAL") break

I kept the input in a loop and checked if it was an int in the loop if so then it breaks the loop.

Profile icon
ElvisNguyen

for example: when the user enter a number than it is ok, but when they enter "non-numerical" input such as abc or [email protected]#. It will tell themto "That is not an Numerical, Please ONLY ENTER NUMERICAL". My question is after the message "That is not an Numerical, Please ONLY ENTER NUMERICAL" how do I make it to return back to "Please Enter A Numerical Length For the Triangle: A =" without run the program again. Thank you in advance for helping me out