Presentation is loading. Please wait.

Presentation is loading. Please wait.

Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.

Similar presentations


Presentation on theme: "Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question."— Presentation transcript:

1 Magic 8 ball

2 "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question and then display the answer as long as the user wishes to continue. Store eight Magic Eight Ball answers in an array. For every question that a user asks, an answer should be randomly selected from the list of answers. You are free to make up any answers you wish.

3 Task 1.... We are going to make our own version of Magic 8 Ball on Python. But first... Draw an algorithm to ensure we have thought about the contents and order of our program...

4 Now to Python A few things you might need to know first...

5 Variables A variable is like a box where we can store a value. To put a value in a variable we use the = symbol

6 A List A list is something we can use in Python to store lots of items in one variable. The square bracket can be used to retrieve an item. The number in the squared bracket is called an Index and starts from 0

7 Order of Lists - We Start at Zero! (red writing is what the computer outputs) Fruit = [‘apples’, ‘pears’, ‘oranges’, ‘bananas’] print (Fruit) Apples, pears, oranges, bananas print (Fruit[0] ) apples print (Fruit[2] ) oranges

8 Getting a Random Value from the Fruit list Import random print (Fruit[random.randint(0,3)] ) Range of numbers starting at 0 and ending at 3 (because you have 3 items in your list

9 print (Fruit[random.randint(0, len(Fruit)-1)] ) Range of numbers starting at 0 Range of numbers ends at the total number of values in the Fruit list (length – len) minus 1.....why minus 1???? Getting a Random Value from the Fruit list when the Fruit list could be any length

10 Adding Items to a List - append Fruit = [‘apples’, ‘pears’, ‘oranges’, ‘bananas’] Fruit.append(‘grapes’) Print (Fruit) Apples, pears, oranges, bananas, grapes

11 Removing Items in a list with the Del Statement Fruit = [‘apples’, ‘pears’, ‘oranges’, ‘bananas’] del Fruit [01] Print (Fruit) Apples, oranges, bananas

12 You should now know all you need to create Magic 8 Ball in Python "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question and then display the answer as long as the user wishes to continue.”

13 Extension Task “i God” was a very popular website with teenagers. Click on this link to see what it was like. http://www.titane.ca/ Think about the programming behind this website. Can you create something similar in Python?


Download ppt "Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question."

Similar presentations


Ads by Google