Follow us on Twitter!
Your life is ending one minute at a time. If you were to die tomorrow, what would you do today?
Friday, April 25, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 20
Guests Online: 18
Members Online: 2

Registered Members: 82906
Newest Member: ilija
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

Python program

thehare
Member



Posts: 73
Location: Canada
Joined: 01.05.08
Rank:
God
Posted on 10-08-08 22:41
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:

Code
# Practice
# 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.


If you need help, dont be afraid to ask, just be sure to give the challenge an honest try before you do.



Edited by thehare on 11-08-08 01:29
Author

RE: Python program

spyware
Member



Posts: 4192
Location:
Joined: 14.04.07
Rank:
God
Warn Level: 90
Posted on 11-08-08 00:06
Try setting a PYTHONPATH.

P.S.: Disable your smileys.



img507.imageshack.us/img507/3580/spynewsig3il1.png
"The chowner of property." - Zeph
[small]
Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term.
- Carl Sagan
[center]�Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor?� - Ebert[/ce

Edited by spyware on 18-08-08 19:31
Author

RE: Python program


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 18-08-08 19:30
You can't include the file extensions when importing. Type "import p" instead or just wrap it all in a while loop (with an optional break to exit the program)