PythonFlashcards1 PDF
PythonFlashcards1 PDF
PYTHON(1)
simple programming
name = "fred" print name print "hello " + name + " how are you?"
@whaleygeek python(1) V2
@whaleygeek python(1) V2
COMMENTS
# this is a comment # it allows you to leave reminders # on how the program works
print "hello" # this is also a comment print "bye" # the computer ignores comments
@whaleygeek python(1) V2
@whaleygeek python(1) V2
INPUT
name = raw_input("what is your name?") print "hello " + name age = int(raw_input("how old are you?")) print "next year you will be " + str(age+1)
@whaleygeek python(1) V2
@whaleygeek python(1) V2
ARITHMETIC
a=1.3 b=2.7 c=a+b print c=a-b print c=a*b print c=a/b print
IF
age=10 if age > 16: print "you have left school"
c c c c
@whaleygeek python(1) V2
@whaleygeek python(1) V2
CONDITIONS
a=1 if a==1: print if a!=1: print if a<1: print if a>1: print if a<=1: print if a>=1: print
IF ELSE
age=10 if age>16: print "you can drive a car" else: print "you are not old enough"
@whaleygeek python(1) V2
@whaleygeek python(1) V2
IF ELIF ELSE
age=10 if age<5: print "you elif age<7: print "you elif age<10: print "you elif age<17: print "you else: print "you
10
AND/OR CONDITIONS
a=1 b=2 if a>0 and b>0: print "both are non zero"
11
are at nursery" are at infants" are at juniors" are at secondary school" have left school"
@whaleygeek python(1) V2
@whaleygeek python(1) V2
FOR
name="fred" for ch in name: print ch total=20 for n in range(total): print n for n in range(1,20): print n
12
WHILE
# beans on a chessboard # put 1 bean on first square # put 2 beans on second square # put 4 beans on third square # how long before you have 1000 beans? squares=0 beans=1 total=0 while total<1000: total += beans beans *= 2 squares += 1 print "it takes " + str(squares) @whaleygeek python(1) V2
13
@whaleygeek python(1) V2
15
@whaleygeek python(1) V2
@whaleygeek python(1) V2
16
BOOLEAN (TRUE/FALSE)
again = True while again: print "hello"
17
answer = raw_input("another go?") if answer != "Yes" and answer != "yes": again = False print "thinking..." if again: print "have another go"
@whaleygeek python(1) V2
@whaleygeek python(1) V2
RESOURCES
http://docs.python.org/2/ http://docs.python.org/3/ http://docs.python.org/2/library/idle.html http://docs.python.org/3/library/idle.html http://www.codecademy.com/tracks/python http://code.activestate.com/recipes/langs/python/
18
MORE FLASHCARDS
http://blog.whaleygeek.co.uk @whaleygeek
David Whale IET Schools Liaison Officer, Essex STEM Ambassador, Essex STEM Ambassador, Hertfordshire
@whaleygeek python(1) V2
@whaleygeek python(1) V2
2. Modified form If you wish to modify the flashcards beyond making small typographical error corrections, please download the DOCX version, and remove my twitter handle and contact details from all cards. You may use the generic template to build your own flashcards, but please remove my twitter handle and all contact details before use. You may use and distribute modified flashcards, call them your own or use them for whatever purpose you see fit, providing that you do not restrict my rights to the original form in any way.