Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > Zelaron Gaming > RPGMaker

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
Reply
Posted 2005-02-15, 09:22 PM in reply to kaos's post starting "So if you press "5" it shows "yams" on..."
In my case, it'll always print 'yams (newline) yams" because x is set to 5 before it checks through the loop. That's just a quick way to show the if structure of Python. If you wanted to do something with input, it'd be like this:

Code:
x = int(raw_input("PRESS FIVE FOR YAMS:  "))
if x == 5:
     print "yams"
     print "yams"
     print "yams"
else:
     print "what"
     print "no yams here"
print "done"
You do parentheses the standard way. So the first line would be evaluated like this:

x = int(raw_input("PRESS FIVE FOR YAMS: "))

raw_input is a function that returns a value that the user inputs (unless you tell Python to get its input from a file and not a user. I'm not good enough for that yet). So that function gets done first, since the innermost parentheses is part of the function. The argument "PRESS FIVE FOR YAMS" is the prompt.

So if you input a 5, this is what's done so far:

x = int("5")

Int is the function that returns the value that's put into it, in integer form. Obviously, that goes to:

x = 5

So from there, we do the next part:

Code:
if x == 5:
You use double equal signs to compare values, and from what I know you have to end an if statement with a colon. All comparisons return either true or false. We know for sure that 5 == 5 is true (unless something is really, really screwed up), so it'll do everything in its block, as defined by the indentation.

Code:
     print "yams"
     print "yams"
     print "yams"
That'll print 3 lines of yams. Easy enough. The next line isn't indented, so it's not part of the "true" block. It's checked to see if it would continue this if block. else statements (and elif as well, but I don't have one here) don't run if a preceding block is true. Since the original if statement IS true, this gets skipped:

Code:
else:
     print "what"
     print "no yams here"
And the next line isn't indented, so it's checked to see if it would continue the if statement again. It doesn't, it's a print statement:

Code:
print "done"
So, it'll print the string "done". Here's how the program looks. I ran it from the command line because otherwise the CMD window would close after the "done" part, which is too fast for you to read:

Old
Profile PM WWW Search
BlueCube enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzBlueCube enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
BlueCube
 



 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 07:09 AM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.