Wednesday, April 3, 2013

Gaming Elements, Changing Values, and Simple Functions

     There are 3 basic elements to make an interesting program: Input, processing, and output. These elements you will find in a video game, for example. Input is the buttons the user pushes on the controller, the game system processes what the user did, and then the output is the image displayed on the television screen.
     We are not at that level of programming yet, so let's start simple. The input is what the user types, the program processes what the user typed, and the output is what your program says. We will use the elements when we learn the functions needed to use them. For now, let's move on to the next thing promised in the title: variables.
     We already covered what variables can do, but there is a little more you need to know about them. Type this variable in Python IDLE:

ex3='Bob'

     We already know that if we say print(ex3), we will get "Bob." But, we can give ex3 a different variable, like this:

ex3='Joe'

print(ex3)

Joe

     So, it printed "Joe," not "Bob." When you create a variable, and then create another variable with the exact same name, the original is deleted. That can help if you want to change variables in programs. Also, you can even change the variable by adding a number to the previous one. Try this:

num=5

print(num)

5

num=num + 1

print(num)

6

     See what it did there? Before the new variable is read by Python, the variable is still 5. When you take it and add one to it, that's how you do it. It's sort of hard to explain, but now you know.
     Now, I will tell you about functions and terms used in programming, which some will be used in the next few articles. Here's a list of a few functions:
< means less than.
> means greater than (duh!).
== means exactly equal to.
!= means not equal to.
<= means less than or equal to.
>= means greater than or equal to.
     I will talk about even more functions in the next few articles. I won't name them now because they involve functions you don't know yet. Even the functions I named have to do with what you don't know yet. I'm just preparing you for what you need to know.

No comments:

Post a Comment