ROTNR 0 Report post Posted April 5, 2009 (edited) Hey there guys/girls, So, I have been working in Python for about a Month now, and have learned a lot. It seems similar to other programming languages I have used in the past (PHP, some C/C++). But I still have a few questions, so here is a sample of one of my codes. ##########Help #File#For #(Program name here)########import syshelp="""1. What is this?2. How does this work?3. What did you make this in?4. Back5. Quit"""print helphline = raw_input("Please select 1-5 above: ")while hline not in ('1','2','3','4','5'): hline = raw_input("Please select a number between 1 and five: ")if hline == '1': print("This is a program duh")while hline not in ('1','2','3','4','5'): hline = raw_input("Please enter a number between 1 and 5: ")if hline == '2': print("Through programming :-p")while hline not in ('1','2','3','4','5'): hline = raw_input("Please enter a number between 1 and 5: ")if hline == '3': print ("Python")while hline not in ('1','2','3','4','5'): hline = raw_input("Please enter a number between 1 and 5: ")if hline == '4': import index.pywhile hline not in ('1','2','3','4','5'): hline = raw_input("Please enter a number between 1 and 5: ")if hline == 5: sys.exit()Okay, so I was wondering if there was an easier way to do this... I have tried elif , but it doesn't seem to work correctly. Also, whenever it brings me back to the start page and I go back to the help file and try to get back to the start page, it always just ends the program. Thanks in advance, -Pete Edited April 5, 2009 by ROTNR (see edit history) Share this post Link to post Share on other sites
truefusion 3 Report post Posted April 5, 2009 The way you set up the program doesn't allow it to loop. You never clear the hline variable, therefore holding the value throughout the script, therefore passing by the while loops and the if statements. Assuming the following is what you want, this is the correct way of doing it: #!/usr/bin/env pythonimport syshelp="""1. What is this?2. How does this work?3. What did you make this in?4. Back5. Quit"""print helpwhile True: hline = raw_input("Please select a number between 1 and five: ") if hline == '1': print("This is a program duh") elif hline == '2': print("Through programming :-p") elif hline == '3': print("Python") elif hline == '4': import index.py elif hline == '5': sys.exit() Share this post Link to post Share on other sites
ROTNR 0 Report post Posted April 5, 2009 Thanks a lot man.-Pete Share this post Link to post Share on other sites