Number 1: Introduction
If you've never heard of python or pygame, I will explain it shortly here. Python is a programming language, like C++, and Java, which are the most popular game programming languages. But, I have found that programming does not need to be extremely hard, needing years of experience. The answer is python. However, python may not be as great as C++, or Java, but it IS just as fast, or faster, very high level(meaning very close to english). So, if you came here for a tutorial, you came to the right place.
It can be very hard to find a very good, free tutorial, or book. I had a very hard time, too, but if you look hard enough, you can find bits and pieces of useful information. That's how I learned.
Number 2: Getting Python
Number 3: Your First Program
Your first program is to print out text that says "Hello, World". If you are wondering, it doesn't print in the printer. All it does is make the text appear on the screen.
Type in this text:
print "Hello, World"
It tells the computer to print Hello, World. It's pretty self explanatory. That wraps up this section of the tutorial.
Number 4: Getting User Input
To get user input, use raw_input(). It pauses the program until the user presses enter. Examine this code:
raw_input("Type in your name.")
It gets user input after it prints the text within the quotations. The program run looks like this:
Type in your name. Socool274
Now, we can make it print what you input, but for this, put it in script mode, i don't know what IDE you use, so I can not tell you how.
Type this code:
name = raw_input("Type in your name.")
print "Your name is: ", name
It works by assigning the input to a variable named 'name'. Then, it prints 'Your name is:", but... there is another thing added to the end of it. It prints the value of 'name' after it prints the text.
The program run looks like this:
Type in your name. Socool274
Your name is: Socool274
That wraps lesson four.
Number 5: Conditional, and Sequence Statements
In the last lesson, I taught you how to get user input, and print that input. But this lesson will teach you to make programs that check if this input, or any variable, has a certain value. Look at this code:
name = raw_input("Type in your name.")
if name == "Socool274":
print "Your name is very nice!"
else:
print "Also, a very nice name."
In this program, it has you type in your name, but it checks whether the value of 'name' is equal to 'Socool274', it has a binary value if true, then it does what is within the 'if', but if the value returns false, then it does what is within 'else'.
The program run:
Type in your name. Socool274
Your name is very nice!
Another run:
Type in your name. Joe
Also, a very nice name.
These are called if... else statements, you can do the program without the else. Any kind of binary value true or false kind of thing is called a conditional statement. A sequence statement is something that repeats itself for every item in the sequence.
Look at this code:
for i in range(10):
print i
In the sequence range, there are ten items, as you passed the parameter of ten to the function range(). More on parameters later. It assigns the value of i to the current part of the sequence it's on. So if it's on the first part of the range sequence, it assigns 'i' to 1. While there is still a part of the sequence that has not been used yet, it does what is inside, print i. So ultimately, this program counts to ten.
Look at this code, it's big but not very complicated:
num1 = raw_input("Input the first number to be added to the second number.")
num1 = int(num1)
num2 = raw_input("Input second number.")
num2 = int(num2)
sum = num1 + num2
print "The sum is: ", sum
The run:
Input the first number to be added to the second number. 528
Input second number. 12
The sum is: 540
That wraps it up.
Number 6: While Loops
The while loop is a loop that consistently loops itself if the condition is true.
Look at this code:
whileCounter = 1
while whileCounter < 11:
print whileCounter
whileCounter += 1
The program run:
1
2
3
4
5
6
7
8
9
10
That's right, it's just another way for it to count to ten, I think you can figure it out if you really look at it.
Buh-bye!
Number 7: Practical Uses
Calculator Program
It's a little bit too big to fit on this website, so I'm really going to start writing text documents. With the text document, I am going to add the source code of the calculator, open it with your IDE.
pythongamestestfile.py | |
File Size: | 1 kb |
File Type: | py |
lesson7text.txt | |
File Size: | 0 kb |
File Type: | txt |
Number 8: Comments
lesson8text.txt | |
File Size: | 0 kb |
File Type: | txt |
This lesson is so simple, I am not adding a .py file.
Number 9: Screen Making
Green Screen
number_9_screen_making.py | |
File Size: | 0 kb |
File Type: | py |
Number 10: Congratulations! You've made it to your big choice!
Pygame
Either one you choose, you will still need pygame. Pygame without anything else can be kind of overwhelming to those who are just starting out with python, so this option is for more advanced people. If you choose pygame, click the top link 'Pygame'.
LiveWires
LiveWires is much better for the beginner, as it is made from pygame, it is a higher level module than pygame. If you choose livewires, click the top link 'LiveWires'.