[Tutor] how do I make my code better?
Alan Gauld
alan.gauld at btinternet.com
Tue Aug 19 02:55:35 CEST 2014
On 18/08/14 20:18, keith papa wrote:
> Am a newbie and I decided to code a program that you input a round
> number and spit out the list of names or other information? how do I
> make this better? how do I make the code repeat itself, so I can keep
> asking the program to print out list of names for a variable?
Have you come across the while loop?
It looks like this:
while <some condition>:
do stuff here
So for your program it should look something like:
while True: # loop forever
answer = raw_input(....
if answer = 'quit':
break # exits the loop
elif answer = ....
as before
If while loops are new to you then you will find more info in
the Loops topic of my tutorial (see .sig).
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list