How to repeat a loop once it is finished

Nagy László Zsolt gandalf at shopzeus.com
Thu Oct 15 09:44:59 EDT 2015


> what would be a small thing that I could add to make this thing run again?

Something like this?


TERMINATOR = "STOP"

def read_int(prompt,minvalue,maxvalue):
    while True:
        answer = raw_input(prompt)
        if answer.lower().strip() == TERMINATOR.lower().strip():
            print "User abort."
            raise SystemExit(0)
        try:
            result = int(answer)
            if result<minvalue or result>maxvalue:
                print "Only number between %s and %s are
accepted."%(minvalue,maxvalue)
                continue
        except ValueError:
            print "That is not a number."
            continue
        return result

def main():
    h = read_int("Enter height between 2 and 6:",2,6)
    l = read_int("Enter length between 2 and 6:",1,25)
    price = read_int("Enter price of paing Luxury=170, economy = 45:",1,200)
    y = h*l*price
    print (y/100 + 0.5)

# If you want to do this multiple times:
print("\n\nYou can terminate anytime by giving %s as the
answer.\n\n"%TERMINATOR)
while True:
    main()




More information about the Python-list mailing list