MOM! Phineas and Ferb are … Aims:

Slides:



Advertisements
Similar presentations
Introduction to Probability
Advertisements

Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Bunco Simply speaking, Bunco is a game of dice, played in rounds. Players take turns rolling the dice and trying to accumulate as many points as possible.
Section 5.1 and 5.2 Probability
Mathematics in Today's World
Solve for x. 28 = 4(2x + 1) = 8x = 8x + 8 – 8 – 8 20 = 8x = x Distribute Combine Subtract Divide.
Games of probability What are my chances?. Roll a single die (6 faces). –What is the probability of each number showing on top? Activity 1: Simple probability:
Programming games Reprise on dice game and alternative dice game Homework: [Catch up.]. Finish dice game.
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 15 Chances, Probabilities, and Odds 15.1Random Experiments and.
Polar Bears: A n ice Game CMSC104 Spring 2010 Project 3
VK Dice By: Kenny Gutierrez, Vyvy Pham Mentors: Sarah Eichhorn, Robert Campbell.
How to maketh a Shakespearean fig generator in python
Matlab tutorial course Exercises 4:. Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function,
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
Horse race © Horse race: rules 1.Each player chooses a horse and puts it into a stall. Write your name next to the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Probability And Expected Value ————————————
Main task -write me a program
Section 5.1 What is Probability? 5.1 / 1. Probability Probability is a numerical measurement of likelihood of an event. The probability of any event is.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
1 Lecture 3 Part 1 Functions with math and randomness.
In this chapter we introduce the idea of what it means for something to be truly random. We also investigate techniques for simulating randomness.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
Lesson 4 Using Variables in Python – Creating a Simple ChatBot Program.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
Computer Programming I Module This lesson illustrates how to code for arrays used to store data and how to display your data in listboxes.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
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.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
CS320n – Elements of Visual Programming Assignment Help Session.
Jane wins $21 if a die roll shows a six, and she loses $2 otherwise
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
int [] scores = new int [10];
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Probability and Simulation The Study of Randomness.
Programming Games of Chance
PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.
Probability Test Review (What are your chances of passing?)
1 Copyright © 2014, 2012, 2009 Pearson Education, Inc. Chapter 9 Understanding Randomness.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Section 5.1 and 5.2 Probability
Recap: If, elif, else If <True condition>:
Repetition Structures
Modelling and Simulating Social Systems with MATLAB
BASIC PROBABILITY Probability – the chance of something (an event) happening # of successful outcomes # of possible outcomes All probability answers must.
Conditional Probability
Chapter 5 - Functions Outline 5.1 Introduction
int [] scores = new int [10];
Probability 14.1 Experimental Probability 14.2 Principles of Counting
Data Structures – 1D Lists
Repetition Structures
Module 4 Loops.
Dry run Fix Random Numbers
Topic 1: Problem Solving
int [] scores = new int [10];
Computer Science 2 Tally Arrays 2/4/2016.
Computer Science I: Get out your notes.
JustBasic 10 Mr. Husch.
Statistics and Probability-Part 5
GCSE Computing.
Programming games Reprise on dice game and alternative dice game
Presentation transcript:

MOM! Phineas and Ferb are … Aims: Use random numbers to simulate dice games. Objectives: All: Try out the programming techniques and make a simple dice game. Most: Make a simple two-player dice game. Some: Complete all tasks, including “Guess the Number.”

Computers cannot generate truly random numbers. If you want some truly random numbers, visit: http://www.random.org/ The numbers there are derived from atmospheric noise. The ones supplied by Python are created by a mathematical process. They are properly known as “pseudo-random” numbers. They are good enough for most programming uses. This import statement means: “get me all the modules from random”. Once we have imported them, we can use them. The randint() function is great for returning a random number between two numbers (including both endpoints). randint(1,6) simulates a die.

It's quite easy to write a function that will return a number from 1 to 6. This function simulates the toss of a coin. Task Write a program that simulates 1000 rolls of a dice. Count how many times each possible throw occurs. Print the results.

Lists Did you use a list to complete the last task? It makes the code a lot simpler. Let's look at an example. This is just our standard template, adapted for the die test idea.

Index 1 2 3 Value apple pear plum orange Indexing If we want to find the contents of a particular cell in a list, we use indexing. In Python the indices start at zero. Index 1 2 3 Value apple pear plum orange To get the item at a certain index, just type the list's name and the number in square brackets. Once you are used to the idea that indices start at zero, you'll have no problems with this.

First we make a list with the same number of elements as there are sides on the die we are testing. Each element in the list is intialised to zero. They will be used to count how many times each number gets rolled. Then we use a for loop. Each time we use the random number that's generated to choose one of the cells in our list. Then that element gets incremented. At the end of the loop, the list will hold the results of the test.

This function takes the list of results and turns it into a string. This makes the results look a bit nicer. As an example, here's the output of a million throws of a six-sided die.

Task Use what you have learned about the random module to make a simple game. It is a two-player game. To begin with, both players should enter their names. The winner of the game is the first to roll a double six. At each round, the program should display the two players' dice scores. If a player wins, the game should announce the winner and exit. If it is a draw, the game should give the option to continue or exit. The output should therefore look something like this.

We are now going to implement a slightly more complex dice game now, it is called “Drop Dead”. The game is simple. You start with five dice. You roll them all together. If any come up as “2” or “5”, you score zero for the round and lose those dice. If you do not get any “2”s or “5”s, then you add the sum of all your dice onto your total. When all your dice have “dropped dead”, it's game over. Here's a sample run.

List Comprehensions We have looked at these before, briefly. We are going to use one in “Drop Dead”. List comprehensions are ways of making a list without using a “for” loop. Task: Use a list comprehension to create a list of odd numbers from 1 to 50.

List comprehension. Use count() to count how many “2”s and “5”s there are in the list of dice throws.

Make “Drop Dead” into a two-player game. Tasks 1: Make “Drop Dead” into a two-player game. Like we did with the double-six game, ask for player names. Display the status at the end of each round. When both players have “dropped dead”, announce the winner. 2: Make a guess the number game. The program should pick a random number (from 1-100). The user should get several chances to guess it. The program should tell the user to guess “higher” or “lower” if he or she does not get the number right.