Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Magic 8 Ball Advanced Task

It is not efficient to store big long lists in a program. Instead we use files. Try out the program below.

1) Open Notepad and enter the list of responses below. Save it in your My Documents as “magic8”
It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yes
Signs point to yes

2) Enter the code below into Python and test it.


import random
import time

f = open(‘n:\magic8.txt','r')

responses = f.readlines()

question = input("Please ask me a question")

time.sleep(2)

print(random.choice(responses))

3) Fully comment your code in Python to make sure you understand what it does.

4) Add more lines to your magic8 text file. Test your program.

You might also like