Computer Science I: Get out your notes.

Slides:



Advertisements
Similar presentations
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Advertisements

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.
Describing Probability
Probability theory and average-case complexity. Review of probability theory.
Introduction to TouchDevelop
Introduction to Artificial Intelligence for Bradley University – CS 521 Anthony (Tony) J. Grichnik Visiting Scientist to Bradley University Caterpillar.
A multiple-choice test consists of 8 questions
MOM! Phineas and Ferb are … Aims:
1. Example 1 – Averages 2. Example 2 – Rolling Dice 3. Example 3 – Number Analysis 4. Example 4 - Divisibility ( while ) Additional Examples on for Loops.
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:
Probability Bingo October 3, D Mathematics.
Computer Science 1 How do you store a bunch of similar stuff?
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
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.
GCSE COMPUTER SCIENCE Practical Programming using Python
Repetition Structures
Chi Squared Test.
for Repetition Structures
AP Java 10/4/2016.
Determining the theoretical probability of an event
Program Options: 10 Minutes online
The Random Class and its Methods
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.
Computer Science II First With files.
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 Dice Project.
Review Dry Run Taking Names Online time Math is Good
Computer Science 2 Review the Bubble Sort
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
Program Options: 10 Minutes online
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 Sorting Pre-Test Discussion/program
Computer Science 2 Tally Arrays 2/4/2016.
What do you do when you don’t know how to get started.
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.
Sorting Develop a sorting algorithm
Computer Science 2 More Trees.
Computer Science 1 while
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?
Computer Science 1 Dice Project.
Warm-up: True/False Dry Run DIV / MOD 2nd If Then Program
Computer Science 1 4/4/2016.
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];
Computer Science 1 while
Dry Run Fix it Write a program
Computer Science And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and.
A bit of Review Review, Dry Run, Program.
Computer Science II First With files.
Presentation transcript:

Computer Science I: 10-4-2016 Get out your notes. Understand how to evaluate expressions with 10 minutes online time to finish program DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…

Program options from Last Class 10 minutes to finish up program 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 Challenge: What is 4(1/1 - 1/3 + 1/5-1/7+1/9…)? Write a program to determine and prove your proposal.

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 20 DIV 9 10 DIV 3 21 DIV 12 9 DIV 10 5 DIV 2

MOD = Remainder of Integer Division

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; 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 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. 1-6 2-30 A pair of 6-sided dice 3-9 odd 12-24 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 8 to 24 even 7 to 35 odd -7 to 21 odd -10 to 10 even A pair of six sided dice

Program options If you are stuck… Hands on, Pseudo-code, Dry run, Flip a coin 100 times, show the total number of heads and tails AND which occurred the most often. 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. Math tutor: User inputs the number of sample addition problems o show. The computer generates the problems and shows them to the user. The user guesses the answers At the end the computer shows how many the user answered correctly.