Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|

Added: | ||||||||

> > |
## Hands OnFunctions and Random numbers ## GoalTo gain experience using functions and learn how to generate random numbers. We will write a game program that allows a person to guess a random number. Guess My Number Game Enter a guess between 1 and 100 : 4 Too low! Enter a guess between 1 and 100 : 6 Too low! Enter a guess between 1 and 100 : 50 Too high! Enter a guess between 1 and 100 : 25 Too low! Enter a guess between 1 and 100 : 35 Too high! Enter a guess between 1 and 100 : 30 Too low! Enter a guess between 1 and 100 : 32 Too low! Enter a guess between 1 and 100 : 34 Too high! Enter a guess between 1 and 100 : 33 Correct! You got it in 9 guesses! ## Step 1Review page on generating random numbers. Questions: 1. How do you generate a number between 1 and 100 (inclusive)? 2. How do you generate a double number between n and m where 0 <= n < m?
Write and test functions:
<-- SyntaxHighlightingPlugin -->
<-- end SyntaxHighlightingPlugin --> ## Step 2Using the functions above write the number guessing game shown in the introduction. ## Step 3Write a program that generates 100 numbers between 1 and 50. What is the average of these numbers? Can you compute the median of the numbers? |

View topic | History: r2 < r1 | More topic actions...

Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Ideas, requests, problems regarding TWiki? Send feedback

Ideas, requests, problems regarding TWiki? Send feedback