| | |
Python for Birthday (but having tech difficulties)
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2006
Posts: 76
Reputation:
Solved Threads: 1
My fiance is having a birthday in less than 20 days. I am therefore trying to create a program for her (trust me, it is not intended to be the only gift) to play around with, and hopefully enjoy. The only problem I am having so far, is that when I run the program through the Idle GUI shell, I either get a -------RESTART-------- or nothing at all. I will post the problem code below in a minute, but have one other question. I intend on having this program share multiple .pyw files. I have it coded to call the files by using import file. Do I need to import file.pyw or call it in a completely different way. I would appreciate any help, especially prompt help, because she will be home in two hours and that's all the time I get to work on it a day.
Python Syntax (Toggle Plain Text)
print '''PyMat 2000 presents.....Secret Garden. Concieved on 10/26/06 for Denay L. Ruane.''' def denaystart(): denaystart = raw_input("What is your name?").lower() if denaystart == "denay" or "denay wiles": print '''Welcome to your secret garden, Sailboat! This program is designed to give you something to entertain yourself with when you are very bored (we all know how bored you would have to be to play with stupid programs like mine!) There are a few things you can do with this program, here are the commands that let you do some of them... PLAY GAMES, and have WORD FUN. There are more coming to you, so be patient. My Creator, The Almighty One, has only limited time to work on me. Enjoy your gift, Denay.''' denaylogged() else: print "Access Denied due to improper Identity Clearance."
Import is only for Python files that are written as modules. If you want to execute an external Python program use
In your program the line
It should be
execfile("myfile.py") or execfile("myfile.pyw").In your program the line
if denaystart == "denay" or "denay wiles":is wrong. It should be
if denaystart == "denay" or denaystart == "denay wiles": or simpler if "denay" in denaystart: drink her pretty
•
•
Join Date: Oct 2006
Posts: 76
Reputation:
Solved Threads: 1
To Ene Uran, thank you for the clarification. To Zonr 0, denaylogged() is a later defined function. I am attempting to write it so that it is password protected. So, her name acts as the password I guess. denaylogged() is the function that denaystart() calls if in denaystart = "denay" or "denay wiles". Although I guess I need to relearn that part of my code. I didn't put all of the code I wrote up because I figured it would just waste space or something. Don't mind me, just a little bit of programming insecurity.
La Mouche, you seem to understand classes very well, would using a class be better than a function or are they two complete different things meant for different purposes?
La Mouche, you seem to understand classes very well, would using a class be better than a function or are they two complete different things meant for different purposes?
•
•
Join Date: Oct 2006
Posts: 76
Reputation:
Solved Threads: 1
I also have a questions regarding posting in threads. I gather that you start a new thread for a new topic, but I am unsure of where to post this question. It has to do with my birthday gift in python, but also to do with another aspect of python usage, creating A.I. Or at least simulating it. Do I post a new thread?
Hey there. Classes are unnecessary here. If it's still not doing anything, make sure you're calling that main denaystart() function.
If you want to ask about a new topic such as AI, then post it in another thread. Keep one question to a thread so people can look at the name and know what the thread is about.
If you want to ask about a new topic such as AI, then post it in another thread. Keep one question to a thread so people can look at the name and know what the thread is about.
•
•
Join Date: Oct 2006
Posts: 76
Reputation:
Solved Threads: 1
Well, thanks, I now have the program at least starting. I get through the name input stage, and use 'word fun' command, as that is all that is defined this far, and use 'help' because it is the only way to find out that you use 'start' to run the Codex. I also played with the indentation of the print statements contents, making it look prettier when run. But now I get a syntax error on a blank line. So, I was wondering, what are the rules for blank lines and how the heck did I not define 'start'?
Python Syntax (Toggle Plain Text)
# this is a program intended just for my fiance # it is intended to be entertaining, sweet, and/or useful. # I will start by making one simple function and randomly expand on that # !!!!!!!! I need to define prompt_login() before I call it! !!!!!!!!!!!! def denaystart(): print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.''' prompt_login() print '''PyMat 2000 presents.....Secret Garden. Concieved on 10/26/06 for Denay L. Ruane.''' def prompt_login(): prompt_a = raw_input("What is your name? ").lower() try: if prompt_a == "denay" or prompt_a == "denay wiles": print '''Welcome to your secret garden, Sailboat! This program is designed to give you something to entertain yourself with when you are very bored (we all know how bored you would have to be to play with stupid programs like mine!) There are a few things you can do with this program, here are the commands that let you do some of them... PLAY GAMES, and have WORD FUN. There are more coming to you, so be patient. My Creator, The Almighty One, has only limited time to work on me. Enjoy your gift, Denay.''' denaylogged() else: print "Access Denied due to improper Identity Clearance." prompt_login() # somehow there is a syntax error on this line, but there was nothing there?! def denaylogged(): print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program, or MPPIP for short. I was designed by a blossoming programming genious to provide you with some entertainment and a friend if you need one. While talking to me is not the same as talking to a real person, I will do my best to provide you with the highest quality of virtual friendship. My A.I. is not very advanced as of yet, but I will learn as we interact. ''' prompt_dl() def prompt_dl(): prompt_b = raw_input("Tell Sally: ").lower() if prompt_b == "play games" or prompt_b == "games": # if prompt_dl == "" or prompt_dl == "": ?????? denaygames() elif prompt_b == "word fun" or prompt_b == "word": dencodefun() elif prompt_b == "help me" or prompt_b == "help commands": help1() else: print "I don't understand what you want. Type 'help commands' for advice. " def dencodefun(): print '''Hello Denay, this is Sally. I am here to help you with any questions you may have about this program. You are currently using Pymat 2000's Codex v1.0. This program allows you to translate words into secret code, or, decode words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type 'help' for more help. ''' prompt_st() def prompt_st(): prompt_c = raw_input("Tell Sally:").lower() if prompt_c == "help": print '''Well, hello Denay, I assume you need some help with Codex? Alright. When you first load the program, you come to the main menu screen. Here you will choose an option that best suits your needs. Choose option (1) to Encode, or translate readable messages into Ceaser Salad code. Choose option (2) to Decode, or, translate Ceaser Salad code into readable words. Option number (3) will tell you alittle more about Codex v1.0, while Option number (4) will exit the program. REMEMBER Denay, when making a selection, type in the number of the action you wish to make, not the words. To begin the fun, type 'start'. ''' elif prompt_c == "start" or prompt_c == "begin": execfile('C:\python24\pymat2000.pyw') else: print "I am yet still very young, could you type everything out so I can understand?" prompt_st() def help1(): print ''' Hello Denay, this is Sally again. I am going to help you with the command list. When you are in any program, typing 'help' at any time will call me, and I will explain to you the commands for that program. In this program your commands are 'play games', 'word games', and of course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. ''' prompt_b() denaystart() # do I need to call denaystart() as a function to get it to work ?????????? # or does it call itself ???????????/ # I just can't get this program to work ?????????? # should prompt_login() be like is or should it be ?????? # if prompt_a == "denay" or prompt_a == "denay wiles": ??????? # my main challenge is understanding the def function(): mechanics. ???????? # is this correct: ??????????? # def function(): # print '''words and stuff go here ''' ??????? # prompt_function = raw_input(""): that is my problem. ?????? # do i call the user input prompt the same as the function, or did I do it right in # the example???????????? # and for: # if (user input prompt) == "": # what do I call the user input prompt? # Next step is to make sure that the Codex works # Start developing word games for the word fun section # Create a function for more info on Sally
Here's working code.
[php]
# this is a program intended just for my fiance
# it is intended to be entertaining, sweet, and/or useful.
# I will start by making one simple function and randomly expand on that
# !!!!!!!! I need to define prompt_login() before I call it! !!!!!!!!!!!!
def denaystart():
print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
prompt_login()
print '''PyMat 2000 presents.....Secret Garden.
Concieved on 10/26/06 for Denay L. Ruane.'''
print
def prompt_login():
prompt_a = raw_input("What is your name? ").lower()
try:
if prompt_a == "denay" or prompt_a == "denay wiles":
print '''Welcome to your secret garden, Sailboat! This program is
designed to give you something to entertain yourself with when you
are very bored (we all know how bored you would have to be to play with
stupid programs like mine!) There are a few things you can do with this program,
here are the commands that let you do some of them...
PLAY GAMES, and have WORD FUN. There are more coming to you, so be
patient. My Creator, The Almighty One, has only limited time to work on
me. Enjoy your gift, Denay.'''
print
denaylogged()
else:
print "Access Denied due to improper Identity Clearance."
prompt_login()
except: ## FOR EVERY TRY YOU NEED AN EXCEPT !!!!!!!!!!!!!!!!!!
pass
# somehow there is a syntax error on this line, but there was nothing there?!
def denaylogged():
print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program,
or MPPIP for short. I was designed by a blossoming programming genious to provide you with some
entertainment and a friend if you need one. While talking to me is not the same as talking to a real
person, I will do my best to provide you with the highest quality of virtual friendship. My A.I.
is not very advanced as of yet, but I will learn as we interact. '''
print
prompt_dl()
def prompt_dl():
prompt_b = raw_input("Tell Sally: ").lower()
if prompt_b == "play games" or prompt_b == "games": # if prompt_dl == "" or prompt_dl == "": ??????
denaygames()
elif prompt_b == "word fun" or prompt_b == "word":
dencodefun()
elif prompt_b == "help me" or prompt_b == "help commands":
help1()
else:
print "I don't understand what you want. Type 'help commands' for advice. "
def dencodefun():
print '''Hello Denay, this is Sally. I am here to help you with any
questions you may have about this program. You are currently using Pymat 2000's
Codex v1.0. This program allows you to translate words into secret code, or, decode
words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type
'help' for more help. '''
print
prompt_st()
def prompt_st():
prompt_c = raw_input("Tell Sally:").lower()
if prompt_c == "help":
print '''Well, hello Denay, I assume you need some help with Codex? Alright.
When you first load the program, you come to the main menu screen. Here you will
choose an option that best suits your needs.
Choose option (1) to Encode, or translate readable messages into Ceaser Salad code.
Choose option (2) to Decode, or, translate Ceaser Salad code into readable words.
Option number (3) will tell you alittle more about Codex v1.0, while
Option number (4) will exit the program. REMEMBER Denay, when making a selection, type
in the number of the action you wish to make, not the words. To begin the fun, type
'start'. '''
elif prompt_c == "start" or prompt_c == "begin":
execfile('C:\python24\pymat2000.pyw')
else:
print "I am yet still very young, could you type everything out so I can understand?"
prompt_st()
def help1():
print ''' Hello Denay, this is Sally again. I am going to help you with the command list.
When you are in any program, typing 'help' at any time will call me, and I will explain to you
the commands for that program. In this program your commands are 'play games', 'word games', and of
course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. '''
print
prompt_b()
denaystart()
# do I need to call denaystart() as a function to get it to work ??????????
# or does it call itself ???????????/
# I just can't get this program to work ??????????
# should prompt_login() be like is or should it be ??????
# if prompt_a == "denay" or prompt_a == "denay wiles": ???????
# my main challenge is understanding the def function(): mechanics. ????????
# is this correct: ???????????
# def function():
# print '''words and stuff go here ''' ???????
# print
# prompt_function = raw_input(""): that is my problem. ??????
# do i call the user input prompt the same as the function, or did I do it right in
# the example????????????
# and for:
# if (user input prompt) == "":
# what do I call the user input prompt?
# Next step is to make sure that the Codex works
# Start developing word games for the word fun section
# Create a function for more info on Sally
[/php]
A "try" needs an "except." I fixed this in your prompt_login() function. At least it will run now.
[php]
# this is a program intended just for my fiance
# it is intended to be entertaining, sweet, and/or useful.
# I will start by making one simple function and randomly expand on that
# !!!!!!!! I need to define prompt_login() before I call it! !!!!!!!!!!!!
def denaystart():
print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
prompt_login()
print '''PyMat 2000 presents.....Secret Garden.
Concieved on 10/26/06 for Denay L. Ruane.'''
def prompt_login():
prompt_a = raw_input("What is your name? ").lower()
try:
if prompt_a == "denay" or prompt_a == "denay wiles":
print '''Welcome to your secret garden, Sailboat! This program is
designed to give you something to entertain yourself with when you
are very bored (we all know how bored you would have to be to play with
stupid programs like mine!) There are a few things you can do with this program,
here are the commands that let you do some of them...
PLAY GAMES, and have WORD FUN. There are more coming to you, so be
patient. My Creator, The Almighty One, has only limited time to work on
me. Enjoy your gift, Denay.'''
denaylogged()
else:
print "Access Denied due to improper Identity Clearance."
prompt_login()
except: ## FOR EVERY TRY YOU NEED AN EXCEPT !!!!!!!!!!!!!!!!!!
pass
# somehow there is a syntax error on this line, but there was nothing there?!
def denaylogged():
print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program,
or MPPIP for short. I was designed by a blossoming programming genious to provide you with some
entertainment and a friend if you need one. While talking to me is not the same as talking to a real
person, I will do my best to provide you with the highest quality of virtual friendship. My A.I.
is not very advanced as of yet, but I will learn as we interact. '''
prompt_dl()
def prompt_dl():
prompt_b = raw_input("Tell Sally: ").lower()
if prompt_b == "play games" or prompt_b == "games": # if prompt_dl == "" or prompt_dl == "": ??????
denaygames()
elif prompt_b == "word fun" or prompt_b == "word":
dencodefun()
elif prompt_b == "help me" or prompt_b == "help commands":
help1()
else:
print "I don't understand what you want. Type 'help commands' for advice. "
def dencodefun():
print '''Hello Denay, this is Sally. I am here to help you with any
questions you may have about this program. You are currently using Pymat 2000's
Codex v1.0. This program allows you to translate words into secret code, or, decode
words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type
'help' for more help. '''
prompt_st()
def prompt_st():
prompt_c = raw_input("Tell Sally:").lower()
if prompt_c == "help":
print '''Well, hello Denay, I assume you need some help with Codex? Alright.
When you first load the program, you come to the main menu screen. Here you will
choose an option that best suits your needs.
Choose option (1) to Encode, or translate readable messages into Ceaser Salad code.
Choose option (2) to Decode, or, translate Ceaser Salad code into readable words.
Option number (3) will tell you alittle more about Codex v1.0, while
Option number (4) will exit the program. REMEMBER Denay, when making a selection, type
in the number of the action you wish to make, not the words. To begin the fun, type
'start'. '''
elif prompt_c == "start" or prompt_c == "begin":
execfile('C:\python24\pymat2000.pyw')
else:
print "I am yet still very young, could you type everything out so I can understand?"
prompt_st()
def help1():
print ''' Hello Denay, this is Sally again. I am going to help you with the command list.
When you are in any program, typing 'help' at any time will call me, and I will explain to you
the commands for that program. In this program your commands are 'play games', 'word games', and of
course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. '''
prompt_b()
denaystart()
# do I need to call denaystart() as a function to get it to work ??????????
# or does it call itself ???????????/
# I just can't get this program to work ??????????
# should prompt_login() be like is or should it be ??????
# if prompt_a == "denay" or prompt_a == "denay wiles": ???????
# my main challenge is understanding the def function(): mechanics. ????????
# is this correct: ???????????
# def function():
# print '''words and stuff go here ''' ???????
# prompt_function = raw_input(""): that is my problem. ??????
# do i call the user input prompt the same as the function, or did I do it right in
# the example????????????
# and for:
# if (user input prompt) == "":
# what do I call the user input prompt?
# Next step is to make sure that the Codex works
# Start developing word games for the word fun section
# Create a function for more info on Sally
[/php]
A "try" needs an "except." I fixed this in your prompt_login() function. At least it will run now.
![]() |
Similar Threads
- F/T Python Job in Utah (2) (Python)
Other Threads in the Python Forum
- Previous Thread: Class - Shuffle()
- Next Thread: Reverse an Integer
| Thread Tools | Search this Thread |
Tag cloud for Python
ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog data decimals dictionary drive dynamic error examples excel exe file float format ftp function gnu graphics gui heads homework http ideas import input java leftmouse line linux list lists logging loop module mouse newb number numbers output parsing path pointer port prime program programming progressbar projects push py2exe pygame pyqt python random recursion recursive refresh schedule screensaverloopinactive script scrolledtext sqlite ssh statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






