-1

Im a student, and just started learning python a month back, so right now, I have only learnt the basics. My teacher had given me a question like this, and the problem is, I dont know how to rerun a program, suppose, after finding the area of a particular shape, I want it to loop back to printing the first statement. Is there any way of doing that without re-running the program using the "F5" key?

 print "1. Triangle"
 print "2. Circle"
 print "3. Rectangle"

 shape= input("Please Select the serial number =")

 if shape==1:
     a=input("Base =")
     b=input("Height =")
     area=0.5*a*b
     print area
 if shape==2:
     a=input("Radius =")
     area=3.14*a*a
     print area
 if shape==3:
     a=input("Width")
     b=input("Length")
     area=a*b
     print area
Jeroen
  • 1,168
  • 1
  • 12
  • 24

1 Answers1

0

If you want to restart, just use a simple while loop.

while True:
    # Your lovely code

Then just put some validation at the end:

    again = raw_input("Play again? ")
    if again.startswith('n') or again.startswith('N'):
        break
    else: 
        continue
Zizouz212
  • 4,908
  • 5
  • 42
  • 66