| We hope you enjoy your visit. You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you are already a member please log in to your account to access all of our features: |
| Python Tutorial: Input and Output | |
|---|---|
| Tweet Topic Started: Oct 26 2009, 06:26 PM (1,292 Views) | |
| Sothh | Oct 26 2009, 06:26 PM Post #1 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
This is the first Python tutorial. It teaches some of the basics of the language. It is written for people going from GML to Python, so some of it may sound silly for the more experienced programmers. I use Python 2.5.2 if thats any help. OK, so you have download Python. You run it and... WHAT THE CRAP??? How am I going to program in this??? OK, so starting with the Command Prompt-style interface might have been a little much. Lets try something easier. Get your lazy butt to the start menu and open IDLE (Python GUI). See? That's much better. Now there's something you should know. Python is an interpreted language. This means that you don't compile anything. So you can basically modify your program as you go. Of course, if you are writting a program, you will want to say your code. So instead of directly typing into the prompt, go to File>New Window. Now you have a nice little window where you can enter your code. So lets start writting... this is a VERY SIMPLE program that takes what you types and returns it back.
Now save and run. OK, lets look at what our code does. "while 1:" This creates a loop. Its like the step event in Game Maker. Note that its followed by a ":". " raw_input()" This is your basic input function. See the TAB? You have to do that in Python after you call a while or if statment. OK, lets try something harder.
See the ("Enter number: ")? That shows the raw_input question. As you have seen above, you don't have to have this. "print" This simply tells Python to print a text to screen. It it followed by the text in "". I then added a comma, and the value "number". You can also do print "Your number was: ", number, "See how cool?" raw_input, and print are the most basic forms in input and output. And you could write entire programs using just them. Comments are another important part of any program. To do comments you type #Comment. There is one more important thing you need to know, and that is the "if" statment. Here are the basics.
We use two == instead of the one in GML. I hope this will help you on the fun journey to Python programming. Edited by Sothh, Oct 27 2009, 07:57 PM.
|
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| Dr. Best | Oct 26 2009, 09:18 PM Post #2 |
|
Administrator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Use the [code ] tag and it will display your tabs. Since the white spaces are relevant in Python you really should have them in a tutorial for starters. |
![]() |
|
| MysteriXYZ | Oct 27 2009, 03:17 PM Post #3 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Hey, nice initiative .It's definitely a good idea to get people interested in using Python . Once you get used to it, you'll realize that it's a lot easier to use than GML - and more powerful at the same time.Actually that's how you should've been doing it in GML also . Otherwise it makes your code confusing: are you assigning a value ("="), or making a comparison ("==")? See, that's another problem with GML: it tries to be "easy" by offering different ways to express the same thing ("and" or "&&", a ";" or not, etc.), leading to ambiguous syntax and ultimately, bugs. Being used to this "relaxed" kind of coding also makes it harder to move on to other programming languages which are more strict (with good reason).By the way, you could've added some comments to the code, to show how that's done, as it's a fundamental part of any program. Missed opportunity there to talk about Python in Interactive Mode. You can do quite a lot at the interactive prompt, and it happens very often that you'll want to try out some very simple things there, just to remind yourself again of how they work. In the simplest case, you can just use it as a calculator. You should have started with this, because it is far more basic (and for simpler things) than Python in Script Mode. Be even less lazy and download PyScripter, which is a lot better. It may look a bit daunting, but you can customize it completely. Spend some time getting familiar with it, and you'll never want another Python editor again. Anyway, I hope my comments didn't discourage you, because I do appreciate someone taking the time to write Python tutorials .
|
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| Sothh | Oct 27 2009, 07:59 PM Post #4 |
|
Shaman Of Time
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Yea, its my fist tutorial, and I am new at Python. I fixed most of it. I don't use PyScripter my self (yet) so I was not going to put it in the tutorial. Thanks for the sugestions though. |
|
“You can’t outrun Death forever. But you can make the Bastard work for it.” Major Korgo Korgar “Last of The Lancers” - AFC 32 (Andromeda Ascendant Record Database) | |
![]() |
|
| « Previous Topic · Tutorials · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)



.
. Once you get used to it, you'll realize that it's a lot easier to use than GML - and more powerful at the same time.
. Otherwise it makes your code confusing: are you assigning a value ("="), or making a comparison ("==")? See, that's another problem with GML: it tries to be "easy" by offering different ways to express the same thing ("and" or "&&", a ";" or not, etc.), leading to ambiguous syntax and ultimately, bugs. Being used to this "relaxed" kind of coding also makes it harder to move on to other programming languages which are more strict (with good reason).
.
9:02 PM Jul 11