Computer Science I: 10-6-2015 Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…

Slides:



Advertisements
Similar presentations
E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Advertisements

Summer 2012 Instructor: Hassan Khosravi
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Clear your desk for your quiz. Unit 2 Day 8 Expected Value Average expectation per game if the game is played many times Can be used to evaluate and.
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Exercise 4 1. Write a program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. Let the program toss the.
Math notebook, pencil, and possibly calculator. Definitions  An outcome is the result of a single trial of an experiment.  The sample space of an experiment.
Describing Probability
Polar Bears: A n ice Game CMSC104 Spring 2010 Project 3
Probability theory and average-case complexity. Review of probability theory.
Introduction to Artificial Intelligence for Bradley University – CS 521 Anthony (Tony) J. Grichnik Visiting Scientist to Bradley University Caterpillar.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
A multiple-choice test consists of 8 questions
Warm up: Solve each system (any method). W-up 11/4 1) Cars are being produced by two factories, factory 1 produces twice as many cars (better management)
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
MOM! Phineas and Ferb are … Aims:
Chapter 11 – Understanding Randomness 1. What is a random event? Nobody can guess the outcome before it happens. Let’s try an experiment. On the next page.
From Randomness to Probability
Math 15 – Elementary Statistics Sections 7.1 – 7.3 Probability – Who are the Frequentists?
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
1. Example 1 – Averages 2. Example 2 – Rolling Dice 3. Example 3 – Number Analysis 4. Example 4 - Divisibility ( while ) Additional Examples on for Loops.
1.4 Equally Likely Outcomes. The outcomes of a sample space are called equally likely if all of them have the same chance of occurrence. It is very difficult.
The Wonderful World… of Probability. When do we use Probability?
5.1 Probability in our Daily Lives.  Which of these list is a “random” list of results when flipping a fair coin 10 times?  A) T H T H T H T H T H 
Truth and while Today 15 Minutes online time to finish the random/Swing programs. Truth tables: Ways to organize results of Boolean expressions. Note Taking:
Section 5.1.  Three ways to answer this question: 1. Actually carry out an experiment 2. Develop a probability model 3. Start with a model, and then.
Java Review if Online Time For loop Quiz on Thursday.
Probability Bingo October 3, D Mathematics.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
Computer Science 1 How do you store a bunch of similar stuff?
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Experiments, Outcomes and Events. Experiment Describes a process that generates a set of data – Tossing of a Coin – Launching of a Missile and observing.
AP Java Java’s version of Repeat until.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
2-6 Probability Theoretical & Experimental. Probability – how likely it is that something will happen – Has a range from 0 – 1 – 0 means it definitely.
AP Java 10/1/2015. public class Rolling { public static void main( String [] args) public static void main( String [] args) { int roll; int roll; for.
Chi Squared Test.
AP Java 10/4/2016.
ECS10 10/10
Review Finish program Graphics Programming
Introduction to pseudocode
Chapter 17 Thinking about Chance.
Computer Science 1 Online time to complete/enhance second repeat program Be able to read and write a program that uses the ‘case’ statement.
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
Truth tables: Ways to organize results of Boolean expressions.
Repeat Day2 Dry Run Second Repeat Program
COUNTING AND PROBABILITY
int [] scores = new int [10];
Computer Science 1 Warm-up: True/False Dry Run
Computer Science 2 Tally Arrays 2/4/2016.
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 Online time for Graphics Program Random review
How can you make a guessing game?
Computer Science II Second With files.
Computer Science 2 More Trees.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Warm-up: Dry Run DIV / MOD 2nd If Then Program
How can you make a guessing game?
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
Computer Science I: Get out your notes.
Dry Run Fix it Write a program
Computer Science 1 Review and finish Number base conversion
Random Numbers while loop
int [] scores = new int [10];
Dry Run Fix it Write a program
Presentation transcript:

Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/… Get out your notes.

Learning Objectives Review a program that uses a for loop with a dry run. Review DIV and MOD operations. Be able to read a program that uses random numbers. Be able to write a program that uses random numbers.

Dry Run the Following

DIV = Integer Division 1.20 DIV DIV DIV DIV DIV DIV DIV DIV 10

MOD = Remainder of Integer Division 1.20 MOD MOD MOD MOD MOD MOD MOD MOD 10

Random Numbers…why use them? Testing data Modeling Gaming Adding ‘chance’ to something

How do you do it? Seed the computer’s random number generator – Randomize; {Command} Make the computer generate a random number in a given range. – Random command Number:= random(12)+ 2;

Syntax Answer:= random(range) + offset; – Answer:=random(100) + 1; – Coin:= random(2)+1; – Die:= random(6)+1; Answer:= 2*random(range) + offset; – Evans/Odds – Evento100:= 2*random(50)+2; – Oddto99:=2*random(50)+1

Example Program program flipper; var count, coin:integer; begin randomize; for count := 1 to 50 do begin coin:= random(2) + 1; {1 = heads, 2 = tails} if coin = 1 then writeln('Heads') else writeln('Tails'); end; {Of the for loop} end. {Of the program}

Reading code Name the range of values that the following could generate Ans:= random(5); Ans:= random(6)+2; Ans:= random(40)-7; Ans:= 2*random(10)+3; Ans:= 2*random(9)-7;

Writing code Write the random line to generate a number for the following ranges A pair of 6-sided dice 3-9 odd even

Check for Understanding: Find the range of values the following code produces. 1)ans:=random(6)+1; 2)ans:=random(14)+2; 3)ans:=random(7)-4; 4)ans:=random(12)+5; 5)ans:=random(23)+8; 6)ans:=random(50)-5; 7)ans:=random(18)+370; 8)ans:=2* random(10) + 1; 9)ans:=2* random(9) + 6; 10)ans:=2* random(21) + 10; 11)ans:=2* random(100) + 51;

Check for Understanding: Write the line of code to generate the following ranges of values 1.1 to to to to to to to 24 even 8.7 to 35 odd 9.-7 to 21 odd to 10 even 11.A pair of six sided dice

Program options 1.Flip a coin 100 times, show the total number of heads and tails AND which occurred the most often. 2.Roll a pair of 6 sided dice 100 times. Find out which occurs most often, 3 or 11. Show how often each of these rolls occur and which occurs most often. 3.Math tutor: 1.User inputs the number of sample addition problems o show. 2.The computer generates the problems and shows them to the user. 3.The user guesses the answers 4.At the end the computer shows how many the user answered correctly. If you are stuck… Hands on, Pseudo-code, Dry run, Code.

Program options. Input: 10 ages Output: The age of the oldest person. – Push: Also enter names and output the name and age of the oldest person – Push: Show the name and age for the top 3. – Push: Calculate the average age Input: 10 times (in seconds) Output: The fastest time. – Push: Also enter names and output the name and time of the fastest person – Push: Show the name and time for the top 3. – Push: Calculate the average time