![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 |
|
Expert Programmer
|
Re: I'm a Beginner
There was recently a fairly detailed discussion about text-based game design in Python in this forum.
|
|
|
|
|
|
#32 | |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: I'm a Beginner
Quote:
ok now let me run this again. print 'you are at the beginning of a yellow brick road: you see one exit, east'
choice = input ("""enter a command""")
print
if choice == east:
print 'you are in the middle of the yellow brick road: you see two exits, east and west'
choice = input ("""enter a command""")
print
if choice == east:
print 'you are at the end of the yellow brick road, you loose your balance and fall off the face of the earth'
elif choice == west:
print 'you try going back and are killed by the wicked witch of the west'
print 'Thank you for playing my first game'
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Last edited by Chuckiferd; Dec 18th, 2007 at 6:39 PM. |
|
|
|
|
|
|
#33 | |||
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: I'm a Beginner
Quote:
Good question. The only difference between an 'if' command and an 'elif' command, is the 'elif' expression can not be satisifed if the 'if' expression was already satisfied. Here's an example: if 1 == 1:
print "We are at the first block"
elif 1 == 1:
print "We are at the second block"This will output: Quote:
The answer is because the first "if" block already executed. Any "elif" or "else" that proceeds the executed "if" will not be executed. Further demonstrating this fact: if 1 == 1:
print "We are at the 0th block"
if 1 == 1:
print "We are at the 1st block"
if 9 == 0:
print "We are at the 2nd block"
elif 1 == 1:
print "We are at the 3rd block"
elif 1 == 1:
print "We are at block 3 and a half"
else:
print "We are at the 4th block"
if 9 == 0:
print "We are at the 5th block"
elif 9 == 0:
print "We are at the 6th block"
else:
print "We are at the 7th block"This will output: Quote:
Last edited by Sane; Dec 18th, 2007 at 6:58 PM. |
|||
|
|
|
|
|
#34 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: I'm a Beginner
Your code's very close to working. There's just a couple small problems:
If you want the user to enter text, as opposed to a number, you use "raw_input". raw_input("Enter Command: ") is for text.input("Enter Number: ") is for numbers.Then to compare a variable to text, the text has to be wrapped in quotation marks. This is because otherwise it thinks you are trying to refer to a variable name. Variable names do not use quotes. Numbers do not use quotes. Text does use quotes. if choice == "east" compares the variable choice to the text east.if choice == east compares the variable choice to the variable east.if choice == "1" compares the variable choice to the text 1.if choice == 1 compares the variable choice to the number 1.So that gives you now: print 'you are at the beginning of a yellow brick road: you see one exit, east'
choice = raw_input ("""enter a command""")
print
if choice == "east":
print 'you are in the middle of the yellow brick road: you see two exits, east and west'
choice = raw_input ("""enter a command""")
print
if choice == "east":
print 'you are at the end of the yellow brick road, you loose your balance and fall off the face of the earth'
elif choice == "west":
print 'you try going back and are killed by the wicked witch of the west'
print 'Thank you for playing my first game' |
|
|
|
|
|
#35 | |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: I'm a Beginner
I meant the tripple quotes in
Quote:
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
|
#36 |
|
Expert Programmer
|
Re: I'm a Beginner
Triple quotes can contain strings that span multiple lines. Although I am not sure why Sane is using them for strings that do not do so.
|
|
|
|
|
|
#37 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,784
Rep Power: 5
![]() |
Re: I'm a Beginner
@Chuck:
Well you'll soon find out that you need to learn a bit more. When you run into trouble, do some reading up on "Functions" in Python. They can be used to create subroutines, which will be necessary for making anything larger or more complicated. @titaniumdecoy: I used them because he used them. Read my post that used triple quotes on a multiline string. Then his post that used it on a single line string. Then mine that copy pasted his. |
|
|
|
|
|
#38 |
|
Newbie
|
Re: I'm a Beginner
As for the Pong game try http://freshmeat.net/projects/tompong/ simple pong game should help you out.
P.S sorry if this was already posted I admit I didn't read all four pages of post. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Beginner Problem | proudnerd | C++ | 16 | May 18th, 2006 6:48 PM |
| call of a beginner | web_master | HTML / XHTML / CSS | 34 | Dec 6th, 2005 12:08 AM |
| function help for a beginner | melee28 | C | 6 | Sep 5th, 2005 9:45 AM |
| what open source code is good to read for a beginner? | linuxpimp20 | Other Programming Languages | 22 | Aug 30th, 2005 3:01 PM |
| Beginner program problem (else if) | Hadrurus | Java | 13 | Aug 14th, 2005 7:07 PM |