Bloomsbury #100Ideas for Secondary: Computer Science Competition
This competition has now closed. Thank you to everyone who entered and congratulations to lucky winner.
As a little bonus for everyone who entered, I've included the script I created to select the winners at random. I have included 4 versions of the script for you to tinker with and adapt for your own purposes.
PS. Don't forget, you can still purchase a copy of #100Ideas for Secondary: Computing via Bloomsbury and Amazon.
PS. Don't forget, you can still purchase a copy of #100Ideas for Secondary: Computing via Bloomsbury and Amazon.
Random name picker - version 1
Version 1.1 (Using list)
Simple name picker (using a list):
Simple name picker (using a list):
Use the window (above) to test your code.
random_name_picker_v1.zip |
Version 1.2 (Using File handling)
Simple name picker (using a file):
Simple name picker (using a file):
random_name_picker_v12.zip |
Random name picker - version 2 (using tkinter)
Version 2.1 (tkinter)
- tkinter is the default GUI that is shipped with Python. With tkinter, it is easy to create GUIs to use with your Python code such as windows, dialog boxes and buttons.
- Code sample (Simple 'random name picker' using tkinter):
import tkinter
import random root = tkinter.Tk() root.title("Random Name Picker") root.geometry("400x200") #Lists of names students = ["student a", "student b", "student c"] #Pick a name at random from the list. def pickName(): nameLabel.configure(text=random.choice(students)) nameLabel = tkinter.Label(root, text="", font=("Helvetica", 32)) nameLabel.pack() pickButton = tkinter.Button(text="Pick", command=pickName) pickButton.pack() root.mainloop() |
tkinter_name_picker_v1.zip |
Version 2.2 (tkinter with File handling)
- Code sample ('Random name picker' using tkinter and file handling):
import tkinter
import random root = tkinter.Tk() root.title("Random Name Picker") root.geometry("400x200") #Empty list to store students names. students = [] #Import names from students.txt. def importNames(): # Read contents of students.txt and add the contents to the students list. file = open("students.txt","r") line = file.readline() while line != "": students.append(line) line = file.readline() file.close() #Pick a name at random from the list. def pickName(): nameLabel.configure(text=random.choice(students)) #Define font size and type for label. nameLabel = tkinter.Label(root, text="", font=("Helvetica", 32)) nameLabel.pack() #Create buttons. pickButton = tkinter.Button(text="Pick", command=pickName) pickButton.pack() #Main program. importNames() root.mainloop() |
tkinterrandomnamepickerv2.zip |
Taking it further
Share the sample code with your students and have them create their own random name selector or have them modify the code to create a 'Harry Potter-style' sorting hat or 'Shakespearean Insult Generator'!