Python: First Look


In [12]:
#print "Hello, world"
print 2+3
print "2+3=", 2+3


5
2+3= 5

Quick Look: Functions


In [17]:
def hello():
    print "Hello"
    print "Computers are fun"
    print "Oh hey it worked!!!"

In [18]:
hello()


Hello
Computers are fun
Oh hey it worked!!!

In [19]:
def greet(person):
    print "Hello", person
    print "How are you?"

In [20]:
greet("Terry")
greet("Paula")


Hello Terry
How are you?
Hello Paula
How are you?

Practice: Add Two


In [25]:
##Practice Problem: Add Two
## A simple program that adds two to a number 10 times
def main():
    print "This program will add two to an input number ten times."
    x = input("Enter a number: ")
    for i in range(10):
        x = x + 2
        print x

main()


This program will add two to an input number ten times.
Enter a number: 2
4
6
8
10
12
14
16
18
20
22

In [23]:
print x


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-23-2d264e11d975> in <module>()
----> 1 print x

NameError: name 'x' is not defined