Programs for class
Pick a random name
Many educators have their own way of choosing names of learners from their classes in a random fashion. Some may use lollipop sticks in a jar, while others might use a specialised app. There’s nothing better than solving this kind of task with your own little custom app though.Let’s start with a simple description of the solution:- Enter names as a string, separated by commas
- Convert the string to a list of names
- Choose a random name from the list
- Output the random name
Convert a string to a list
This is such a common problem that the solution has been built into the Python programming language. Let’s have a look at how it works:vowels = "a e i o u"
list_of_vowels = vowels.split()
print(list_of_vowels)
.split()
is a built-in Python method which will split any string into a list, and defaults to splitting where there is a space. You can pass in other characters for it to use though.vowels = "a,e,i,o,u"
list_of_vowels = vowels.split(',')
print(list_of_vowels)
Picking random items from a list
Although this is quite a common task, the commands for dealing with randomness are not baked into Python. They are part of the standard library, though. This means that you don’t have to download the code, but it does need to be imported into your program so you can access it.from random import choice
my_list = ['a', 'e', 'i', 'o', 'u']
my_vowel = choice(my_list)
print(my_vowel)
import
lines at the top of you code.Coding the solution
Now you have these commands at your disposal, can you write a program that will pick a random student’s name from a string of student names separated by commas, such as the one below?names = 'Alice,Bob,Carol,Chuck,Craig,Dan,Erin,Eve,Fay,Frank,Grace,Heidi,Judy,Mallory,Olivia,Oscar,Peggy,Sybil,Trent,Trudy,Victor,Walter'
Challenge
Another common task for educators is to deal with test scores. Imagine you have a long string with a student’s test score, followed by their name. Can you write a program that can sort test scores, lowest to highest and/or highest to lowest?Here’s some example data you can use:'54 - Alice,35 - Bob,27 - Carol,27 - Chuck,05 - Craig,30 - Dan,27 - Erin,77 - Eve,14 - Fay,20 - Frank,48 - Grace,61 - Heidi,03 - Judy,28 - Mallory,05 - Olivia,44 - Oscar,34 - Peggy,30 - Sybil,82 - Trent,75 - Trudy,92 - Victor,37 - Walter'
There’s going to be no specific help here, but one thing text-based programmers rapidly learn is to use the internet to find solutions to problems — here are a couple of links to StackOverflow entries that might help you out.Sort a list of stringsReverse a listShare your solutions using a link from Pastebin. Remember that you can also ask for help in the comments section if you need it — as well as helping each other out if you can.Scratch to Python: Moving from Block- to Text-based Programming

Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.
Learn more about how FutureLearn is transforming access to education