Python Forum

Full Version: How can I go back to a specific code line?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi people,

I am new here and I have an issue with one of the exercises of a course I am taking.

Actually, it's not a problem with the exercise, but I want to do something different and can't seem to figure out the way to do it.

Here is the code:

# 28.08.2018 - Phyton Shape Area Calculator #

name = raw_input("Hello, What is your name? ")
print 'Hello ' + name
print 'Area calculator is running'

shape = raw_input("What shape do you want to input? Please enter C for Circle or T for Triangle ")


if shape == 'C':
 radius = float(raw_input("Insert the radius of the circle: "))
 areac = 3.14159 * radius**2
 print 'The area of your circle is ' + str(areac)
  
elif shape == 'T':
  base = float(raw_input('What is the base of the triangle? '))
  height = float(raw_input('What is the height of your triangle? '))
  areat = 0.5 * base * height
  print 'The area of your triangle is ' + str(areat)
  
else:
  print 'Are you stupid?'
I just want the program to go back to the "What shape do you want to input? Please enter C for Circle or T for Triangle " if the user end up inputing the wrong letter (any letter but the 'C' or 'T').

Can anyone help me?

Thanks.
Look into while loops.

To make it simple wrap your input line in a while and break out of it if the user enters an acceptable input.