Python program
Hey everyone, lately I've been learning to program with Python, and the last few hours I've been putting what I learned so far into practice by writing a simple (and useless) program, it has been going good except with my restart option only allows the user to restart once and then I get an error ( I will show you the error and the program below) and could not think of anyway around the program unless the user wants to turn off the program manually and start it again. Well here is the program:
# Made by thehare
#
print " Hello Welcome to my practice 'game'"
print ""
print " This 'game' will ask you how you"
print " are doing and you will respond" # Just the intro
print " by pressing 1,2,or 3 depending on"
print " what you want to do."
print ""
def menu(list, question):
for entry in list:
print 1 + list.index(entry),
print ") " + entry
return input(question) -1
items = [" Good", " Bad", " Don't say anything"] # Defining the menu
loop = 1
print ""
print "Hello How Are You "
print ""
print "Select one of the selections below"
# This is the main program:
#
while loop == 1:
choice = menu(items,"How are you ?")
if choice == 0:
if loop == 1:
print ""
print "That is good "
print ""
loop = 2
if choice == 1:
if loop == 1:
print ""
print "That is to bad "
print ""
loop = 3
if choice == 2:
if loop == 1:
print ""
print "What, are you to good to talk to me? "
print ""
loop = 4
while loop == 2:
print "Have a nice day"
print ""
loop = 0
while loop == 3:
print "Hope your day improves"
print ""
loop = 0
while loop == 4:
print "F$%# off"
print ""
loop = 0
#Below is the part of the program that either ends or restarts the program:
#
while loop == 0:
print ""
print "If you want to try the program again type yes";
a=(raw_input(""))
print ""
if a == 'yes':
print "One second please..."
print ""
loop = 5
elif a == 'no':
print " Goodbye"
print ""
loop = 6
else:
print "Command",a , "is unknown"
print ""
loop = 7
while loop == 6:
print " Hope you enjoyed my program";
print ":-)"
print ""
loop = 1
while loop == 7:
print " Re-open program if needed"
print ""
loop = 1
# This is the restart script
#
while loop == 5:
import p.py
restart_file = open('p.py', 'rd')
reader = py.reader(restart_file)
print ""
print restart_file
# Written By **thehare**
And here is the error I receive:
Traceback (most recent call last): File "C:\Python25\p.py", line 110, in <module> import p.py File "C:\Python25\p.py", line 110, in <module> import p.py ImportError: No module named py
What could I do to solve this program?
Help would be appreciated, and any ideas on what to try to program next would be welcome to.
Thanks thehare
P.S And if you want to save it to your pc save it as p.py, and change the smiley face to a bracket, and the you might have to manualy "tab" the program into position as I don't think that my tabs will go through.