Draw a square:
Full documentation for the turtle module: https://docs.python.org/2/library/turtle.html
Draw 3 shapes
Full documentation for the turtle module: https://docs.python.org/2/library/turtle.html
Tues 21 Feb 2017: KS1 @ King Charles Centre
Wed 22 Feb 2017: KS1 @ St James’s
Wed 14 June 2017: KS2 @ St James’s
Thu 15 June 2017: KS2 @ KCC
Tue 27 June 2017: KS1 @ KCC
Wed 28 June 2017: KS1 @ St James’s
The following starter code is loosely based on the flowchart shown. The function provided is used to check whether a username already exists.
Use the starter code to implement the sections marked #TODO.
The text file, with usernames can be downloaded here.
''' creating usernames uses a file of existing usernames this file is read in and then new usernames are checked against it complete sections marked #TODO ''' # reading in existing usernames def read_usernames(): with open('usernames.csv') as ufile: data = ufile.readlines() usernames = [] for line in data: line = line.strip().split(',') usernames.append(line[4]) # only appends usernames, rest discarded return usernames # checking if username exists # the if condition in this function is equivalent to the one-line return def exists(username): ''' if username in read_usernames(): return True ''' return username in read_usernames() # this writes the data back to the file def write_userdata(udata): with open('usernames.csv', 'a') as ufile: ufile.write(udata) print(udata, 'has been written to the file.') print('Open the file: "usernames.csv" to see the data in the file') #TODO write your code to construct a username below #use the exists() function to check if a username already exists #TODO write the code to construct a comma separated string of the format: # yearofentry, firstname, surname, initial, username\n #TODO call the function write_userdata() with your string
This reads a csv file to get data on stations and miles. Use the starter code below and the linked csv file to solve this.
''' big exam question starter code implment your algorithm below complete the sections starting # TODO ''' # read file and clean up the data def getstationdata(): with open("stationlookupkingston.csv") as tfile: data = tfile.readlines() stationlist = [] for line in data: line = line.strip().split(',') line[1] = int(line[1]) # convert the miles to int stationlist.append(line) return stationlist #send back a 2d list ListOfStations = getstationdata() # list of stations and miles # intro for the user print(''' *********************************************** This section will simulate the card being read. We will assume journey ends at Kingston' Instead of IDs we will use station names *********************************************** ''') # TODO change start to an input from the user start = 'Barnes' #card being read miles = 0 # initialise miles # TODO add a for-loop to iterate through the elements in ListOfStations # TODO find the miles for start - remember it is a 2d list #TODO display the fare based on miles
Download the csv file for the above starter code.
Students need to practice reading and completing algorithms given to them as pseudo code and flowcharts. The following problem has been modified from a past paper. Use the starter code to complete the program and check that the algorithm works:
''' Rail passengers carry a contactless smartcard to pay for train journeys. A processor in the exit barrier calculates the rail fare. The card is swiped at the start and end of each journey. If there is enough money on the card at the end of the journey, the balance is updated and displayed on the barrier screen and the exit barrier opens. If not, the message, “Need to top-up” is displayed and the barrier does not open. ''' # stations and costs for ending Kingston # only london journeys def calculateCost(startStation): zone1 ='waterloo westminster greenpark marble arch' zone2 = 'archway arsenal bermondsey bow hampstead' zone3 = 'barnes bellingham bowe charlton harlesden highgate' zone4 = 'barking brentford eltham greenford hanwell' zone5 = 'becontree brimsdown cheam eastcote hayes' zone6 = 'hillinngdon heathrow ickenham purley romford' zone1 = zone1.split() zone2 = zone2.split() zone3 = zone3.split() zone4 = zone4.split() zone5 = zone5.split() zone6 = zone6.split() if startStation in zone1: return 5.5 if startStation in zone2: return 4.5 if startStation in zone3: return 4 if startStation in zone4: return 3.75 if startStation in zone5: return 3.5 if startStation in zone6: return 3 return 0 #if station not found # end of above function # TODO change startStation to be an input startStation = 'barnes' #for testing only # TODO get balance as a decimal number input payment = calculateCost(startStation) # TODO implement the rest of your algorithm
The bitmap image can be manipulated by a python program. For example, you can replicate some of the filters that can be applied in image-editing software.
This starting code can be used to explore the file structure. It requires the use of slicing and loops to complete it. Apply it to the image provided below.
''' a program to change the brightness of an image pixel by pixel work on the sections marked # TODO ''' # open file and read the binary data with open('skull.bmp', 'rb') as ifile: data = ifile.read() #locate the header and pixel array using slicing header = data[0] #TODO slice to end of header pixel_array = data[0] #TODO slice from end of header to image data #TODO include a test to print the first few bytes of the pixel array #check these using a hex-editor #go through each pixel value and add 50 #make sure to deal with a value that goes over 255 #add the new pixel value to a list called intense pixels intense_pixels = [] #TODO write your loop here #convert the new pixel values into bytes objects intense_pixels = bytes(intense_pixels) #combine header and pixel array new_image = header + intense_pixels # write out the image data into a new file with open('skull_intense.bmp', 'wb') as ifile: ifile.write(new_image) print('finished updating image')
You can use this bitmap image for experimenting.
Last term, Alysha Logan at Hampton Junior School, planned and taught a data-handling unit to Y5. This addressed the following KS2 computing curriculum content:
“select, use and combine a variety of software .. to design and create .. content .. including collecting, analysing, evaluating and presenting data and information”
The unit required pupils to analyse a large set of real data, draw conclusions and present findings as an infographic. Alysha has provided this feedback about the unit:
“[The unit] worked out brilliantly and the children really loved it. I taught it step by step and had them work through it .. which I found to be the best way … They really loved the picture editing software and making the graphs – they seemed to really enjoy seeing their hard work resulting in a visual and unique end product.”
Do contact me if you would like the resources that go with the unit.
Last term, Trafalgar Infant school were shortlisted for and won the Technology in Learning Award presented by Community Education Awards.
Trafalgar Infant school is a unique example of a school where technology has been systematically developed and embedded. They have a well-established and excellent e-school. Jane Burton, the lead for computing, trained some of the children to be digital leaders. Last year, they helped maintain their Rio Olympics e-room.
To support the Olympics e-room, the children commented on the Rio blog post. For this academic year, Jane has set up the school blog for each class.
I am always surprised by Jane’s matter-of-fact response to the issue of children remembering usernames and passwords to make blogging and e-school a success:
“We just train them up.”
If you would like more information about the school and their computing journey, leave a comment or email me and I’ll put you in touch with Jane.