Magic 8-Ball ๐ฎ
Time to give your programs a mind of their own. Python has a toolbox
called random โ you unlock it with one line at the top of your file:
import random
Then you get two brilliant powers:
random.choice() picks a random item out of a list:
flavors = ["vanilla", "mint", "mango"]
print(random.choice(flavors)) # โ a different one each run!
random.randint(a, b) gives a random whole number between a and b
(both ends included) โ perfect for dice:
print(random.randint(1, 6)) # โ 1, 2, 3, 4, 5 or 6
Run your program a few times and watch the answers change. ๐ฒ
Your mission
Build a magic 8-ball fortune teller!
import randomat the top- Make a list called
answerswith at least 6 mysterious replies - Use
input()to ask the user for their question - Print a reply picked with
random.choice(answers) - Print a certainty percentage using
random.randint(1, 100)
Then run it again. And again. It's different every time! ๐ฎ
Your code
Press โถ Run to see what your code does!