Say I use raw_input
like this:
code = raw_input("Please enter your three-letter code or a blank line to quit: ")
under if __name__=="__main__":
How can I let it repeat multiple times rather than just once every time I run the program?
Another question is to write what code can satisfy the condition "or a blank line to quit (the program)".
views:
191answers:
4
+1
A:
a while loop is what you need. i will let you work out the syntax and the condition of the while.h
Adrien Plisson
2009-11-23 06:40:37
A:
if __name__ == '__main__':
input = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
while input:
input = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
inspectorG4dget
2009-11-23 06:41:42
+3
A:
best:
if __name__ == '__main__':
while True:
entered = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
if not entered: break
if len(entered) != 3:
print "%r is NOT three letters, it's %d" % (entered, len(entered))
continue
if not entered.isalpha():
print "%r are NOT all letters -- please enter exactly three letters, nothing else!"
continue
process(entered)
Alex Martelli
2009-11-23 06:58:12
+1
A:
while 1:
choice=raw_input("Enter: ")
if choice in ["Q","q"]: break
print choice
#do something else
ghostdog74
2009-11-23 07:17:25