Python Program Menu and goto start

July 9, 2012 at 03:37:22
Specs: windows xp
hey all I have been using batchfile scripting for a couple of years now and want to learn something else....python...

this is so simple in batch but i cant make it work in python...help me out someone...

print " Python program"
print "************************************* "
print "(1) Open Internet Explorer"
print "(2) Open Firefox"
print "(3) Exit Program"
print "************************************* "

what commands to i use and then go back to the start ?
I think.....

num = raw_input ("what do you want to choose:") # is this right ?

if num == 1:

# i googled this stuff
import os
os.chdir ('C:\Program Files\Mozilla Firefox')
os.startfile ("firefox.exe")
# i googled this stuff

if num == 2: # when second option do i use "ELIF" command ??
import os
os.chdir ("C:\Program Files\Internet Explorer")
os.startfile ("iexplore.exe")
if num == 3:
quit
else:
print "no selection made :P" # is this suppose to happen if i press enter without choosing ? cause it didnt do it for me...


now i have been reading everywhere to use "WHILE" command but the examples are for other things and i cant make it work for me in this ?


See More: Python Program Menu and goto start

Report •


#1
July 10, 2012 at 20:08:09
I would look for a "CASE" statement, I'm sure Python has one. I don't have the helpfile to check...

Report •

#2
July 10, 2012 at 23:14:57
Python has no "case" or "switch" statement. The OP needs to use a series of "if else" statement within a "while TRUE" loop.

Report •

#3
July 10, 2012 at 23:56:30
Ouch, that's what I get for assuming things. Since I screwed that up, here's pseudocode:
num=0
while num<>3 do: # or: while num !=3? you get the idea...
num = raw_input ("what do you want to choose:")
if num==1:
do ONE
end if # or whatever python uses to close a multi-command IF
if num==2:
do TWO
end if
loop
quit

Had to give it a shot


Report •

Related Solutions


Ask Question