Raspberry Pi – Lucky Dip and Random Name Picker

Posted: January 27, 2014 by schoolpiclub in General News

This week we are hoping for a lottery win from our Raspberry Pi Lucky Dip!

Students had to guess the programme as the code was being input – well done to NJ who guess correctly. Here is the code we used:-

import random

nums = []

balls = [i for i in range(1,49)]

random.shuffle(balls)

nums = balls[:6]

print(“Here are your ‘lucky dip’ numbers:”)

print(nums)

print(“Remember to split any winnings with me!”)

 

We then looked at adapting the code to have a Random Student Name Picker. Here is the code for that programme:-

 

import random

names = []

students = [‘name1′,’name2′,’name3′,’name4′,’name5′,’name6′,’name7′,’name8′,’name9′,’name10’]

random.shuffle(students)

names = students[:2]

 

print(“Here are your ‘lucky dip’ students:”)

print(names)

print(“Good luck!”)

 

Advertisements

Comments are closed.