Hue World

Submitted by: Submitted by

Views: 190

Words: 483

Pages: 2

Category: US History

Date Submitted: 03/31/2013 10:57 PM

Report This Essay

CSC 241: Introduction to Computer Science I

Assignment 8 (100 pts) – The Last!

Reading

Review Chapter 6 and read Chapter 7 in Introduction to Computing using Python: An Application Development Focus by Ljubomir Perković, John Wiley & Sons, 2012.

Assignment

Implement the functions below in a file csc241hw8.py and submit through COL.

NOTE!!: You must also add appropriate doc strings (e.g. strings that appear on the line following the function header) to the functions that clearly and concisely describe what the functions are doing.  A submission without doc strings will not earn full credit.

Assignment

1. Write a function game() that teaches children how to add single-digit numbers.  The function should take an integer n as a parameter and ask the child to answer n single-digit addition questions.  The numbers should be chosen randomly from the range [0, 9] (that is including both 0 and 9).  The user will enter the answer when prompted.  Your function should print 'Correct' for correct answers and 'Incorrect' for incorrect answers.  After n questions, the function should print the number of questions answered correctly.  The following shows several sample runs of the function:

[pic]

 

2. Craps is a dice-based game played in many casinos.  Like blackjack, a player plays against the house.  The game starts with the player throwing a pair of standard, six-sided dice.  If the player rolls a total of 7 or 11, the player wins.  If the player rolls a total of 2, 3, or 12, the player loses.  For all other roll values, the player will repeatedly roll the pair of dice until either she/he rolls the initial value again (in which case she/he wins) or 7 (in which case she/he loses).

a. Write a function craps() that takes no parameters, simulates one game of craps, and returns 1 if the player won and 0 if the player lost.  It should also print a history of the rolls so that the player can verify that the function is doing the right thing. ...