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.

Slides:



Advertisements
Similar presentations
Whats your favorite color? a pear a green pear.
Advertisements

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CHAPTER 4 AND 5 Section06: Sequences. General Description "Normal" variables x = 19  The name "x" is associated with a single value Sequence variables:
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
DICTIONARIES. The Compound Sequence Data Types All of the compound data types we have studies in detail so far – strings – lists – Tuples They are sequence.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
CS 177 Week 11 Recitation Slides 1 1 Dictionaries, Tuples.
Using a Web Browser What does a Web Browser do? A web browser enables you to surf the World Wide Web. What are the most popular browsers?
MOM! Phineas and Ferb are … Aims:
Learning the skills for programming Advanced Visual Programming.
By the end of this session you should be able to...
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Built-in Data Structures in Python An Introduction.
Lists. The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 9: Tuples and lists.
Math 15 Introduction to Scientific Data Analysis Lecture 8 Python Programming – Part 2 University of California, Merced.
1. Understand the application of Pseudo Code for programming purposes 2. Be able to write algorithms in Pseudo Code.
Nonvisual Arrays by Chris Brown under Prof. Susan Rodger Duke University June 2012.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Lab 8. Declaring and Creating Arrays in One Step datatype[] arrayRefVar = new datatype[arraySize]; double[] myList = new double[10];
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
SOL 1.8 and 1.9 FRUIT. For each problem: Display the 1 st slide which contains the problem. Have the students place counters on their desks to match.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Creating a mystic meg program A simple program asking the user questions and using their answers to build up a fortune telling in a list.
Algorithms, Part 3 of 3 Topics In-Class Project: The Box
Arrays. Array: Sequence of values of the same type Construct array: Store in variable of type double[ ] new double[10] double[] data = new double[10];
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
GCSE Computing: Programming GCSE Programming Remembering Python.
Python Data Structures By Greg Felber. Lists An ordered group of items Does not need to be the same type – Could put numbers, strings or donkeys in the.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
For Loops & Arrays. my_rect_pink_mc.width = 40 my_rect_pink_mc.alpha =.5 trace my_rect_pink_mc.x= 20 my_rect_pink_mc.y= 20 for (var i:int = 0; i < 250;
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
String and Lists Dr. José M. Reyes Álamo.
YEAR 12 COMPUTER SCIENCE.
Introduction to Arrays
Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do.
Arrays (in Small Basic)
To write a Python program, you first need to open Pyscripter
Learning to Program in Python
I Like… Yes, I do. No, I don’t.
Creation, Traversal, Insertion and Removal
Javascript Game Assessment
Data Structures – 1D Lists
ARRAYS 1 GCSE COMPUTER SCIENCE.
Fruit Random Slide Show Menu
String and Lists Dr. José M. Reyes Álamo.
Remembering lists of values lists
Programming We have seen various examples of programming languages
Inputs and Variables Programming Guides.
How many objects can you create by drawing in the circles?
Python Lists.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Python Basics with Jupyter Notebook
Arrays & Loops.
Arrays & Loops.
Adding and subtracting binomial
Year 8 Computer Science Digital Portfolio
Introduction to Computer Science
Presentation transcript:

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 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.

Task 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...

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

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

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

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

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

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 why minus 1???? Getting a Random Value from the Fruit list when the Fruit list could be any length

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

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

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.”

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