-
Notifications
You must be signed in to change notification settings - Fork 1
PythonResources
Chris Kimpton edited this page Mar 26, 2019
·
13 revisions
Python language covered per CodeClub project
1. About Me
- print('') and multi-line using print(''' ... ''')
- repeat chars - print('&*' * 10)
- maths - print(3 - 1)
- variables - myvar = 1
- input - myvar = input('What...')
- convert to int - int(myvar)
- imports - from random import randint, myvar = randint(1,3)
- conditional logic, like, note the colons and two space (or tab) indent
- if myvar == 1:
- othervar = '2'
- elif myvar == 2:
- othervar = '3'
- else:
- othervar = '4'
3. Turtle Race
- from turtle import *
- moves - forward(100)
- write(0)
- loops, like so - remember colon and indents like above
- for step in range(5):
- write(step)
- forward(20)
4. Team Chooser
- find a char in a string - pos = "123".find('2')
- modulo - % 5 % 2 => 1
- lookup char pos in string - "123"[2] => "3"
- loop chars in string
- for char in mystring:
- add to end of string - a='1', b='2', a+=b => a is now '12'
1?
a = 1
2?
if x < 5:
print "The value is OK."
3?
for i in [1,2,3,4,5]:
print "This is iteration number", i
4?
x = 10
while x >= 0:
print "x is still not negative."
x = x-1
5?
x = input("Please enter a number: ")
print "The square of that number is", x*x
6?
colours = ["red","blue","green"]
print colour[0]
7?
person = { 'first name': "Robin", 'last name': "Hood",
'occupation': "Scoundrel" }
8?
def square(x):
return x*x
print square(2) # Prints out 4
Astro Pi Challenge - until 20 March 2019
https://trinket.io/mission-zero/classroom-code
https://projects.raspberrypi.org/en/projects/astro-pi-mission-zero/
https://astro-pi.org/missions/zero/faq/
http://esamultimedia.esa.int/docs/edu/European_Astro_Pi_Challenge_Mission_Zero_guidelines.pdf
And some useful links
- Free ebooks on learning Python - http://readwrite.com/2011/03/25/python-is-an-increasingly-popu
- Python for Kids - http://www.nostarch.com/pythonforkids
- Python Basics - http://www.amazon.co.uk/Python-Basics-Level-Coding-Club/dp/1107658551/ref=sr_1_15?s=books&ie=UTF8&qid=1417641992&sr=1-15&keywords=python+in+books
- http://jupyter.org/ - more for data analysis - but might be of interest
- http://interactivepython.org/runestone/static/StudentCSP/index.html - interactive ebook to learn python
- http://omz-software.com/pythonista/docs/ios/index.html - Pythonista (iOS Python app), including ios specific modules.
- https://www.idi.ntnu.no/~mlh/hetland_org/writing/instant-python.html - instant python