0

I am running a simple program that takes user info, stores it, manipulates it then prints the results.

The program is intended to be run multiple times in a row and it would be nice to be able to do this without having to exit it and restart it again.

Is there a nice simple way to restart the code that doesn't include having to use while x != y loops.

I have scoured google but can only find very long and complex methods, surely there must be a simple command for this?

J-Thor
  • 5
  • 3
  • 2
    Why are you intent on avoiding a simple `while` loop? Besides, you could always just wrap it in a shell script with a `while` loop ... If you're looking for a goto, I'm afraid Python doesn't offer that. – Rufflewind Aug 27 '14 at 02:19
  • Honestly it's because I have used several already and I am trying to learn new methods since I am new to this. Also I am trying to show diversity throughout the program. If this is the only way to go I will use it but would be nice to know if there are any other ways out there :) – J-Thor Aug 27 '14 at 02:24
  • Try using generators and `map` for your other loops that actually compute things. – jpmc26 Aug 27 '14 at 02:32
  • Ok then i'll look into it although I am unfamiliar with map and multiple generators. If someone could post an example as an answer to the question that would be very helpful and I can give them a best answer vote. – J-Thor Aug 27 '14 at 02:36

1 Answers1

0

If this is your program:

pi = 22./7
print (u"Eureka! \u03C0 == %.2f"%pi)

You can invoke it multiple times by making a function:

def discover_constant():
    pi = 22./7
    print (u"Eureka! \u03C0 == %.2f"%pi)

# Print PI three times:
discover_constant()
discover_constant()
discover_constant()
Robᵩ
  • 163,533
  • 20
  • 239
  • 308