Thursday, 4 February 2016

Variables



#Open test.py (previous lesson).
Remember: right-click > open with IDLE
You are going to use it for testing little snippets of code.

# Variables 1: Copy and paste the following two lines. Then click F5.
a = 7
print (a)

What is happening?

# Variables 2: Delete the previous. Try these three now. Then click F5.
a = 9
b =a
print (b)

# Variables 3: What is happening? Now a longer one.
a = 9
b = a
c = b
d = c
e = d
print (d)

#Variables 4: With input (varying answers)
print ('You favourite word')
a = input ( )
print ('Your favourite word is ' + a)

What is happening?

#Variables 5: With 2 different inputs:
print ('You favourite word')
a = input ( )
print ('You favourite number')
b = input ( )
print ('So you like ' + a + b)

#Variable 6: Your turn. Create more!