V22.0002 - Summer 2010 - Nathan Hull

Assignment #3 - Due: Friday, July 9


1.) Doubles!!

In games with two dice (such as Monopoly), rolling two 6-sided dice and getting the same side or number on both dice is called doubles. Write a program which first prompts the user for the number of sides to the dice (as "regular" dice have 6 sides, but D&D dice could have 10, 12, or 30 sides etc). Then you program should keep "rolling the dice" until it gets three sets of doubles. The program should tell the user how many "rolls" were required to get three sets of doubles with this pair of "dice"!

Sample input:

How many sides on your dice? 6? 10? 12? 30? 6

Sample output:

1. die number 1 is 5 and die number 2 is 3.
2. die number 1 is 2 and die number 2 is 4.
3. die number 1 is 1 and die number 2 is 1.
4. die number 1 is 3 and die number 2 is 3.
  You got a double (3).

. . .

Three sets of doubles! Finally! On try number 31!

This program should be named as follows: lastname_firstname_assign3a.py (for e xample, shakespeare_will_assign3a.py)

2.) Factorials

Factorials are used in many applications in mathematics as the result grows very quickly. So while 5! = 120, 10! = 3,628,800. Factorials are used to calculate permutations for example: n! represents the number of ways to arrange n distinct objects into a sequence (which is something that Hindu scholars had figured out in the 12th century.) The notation n! was introduced by Christian Kramp in 1808. See http://primes.utm.edu/glossary/xpage/Factorial.html or http://notaboutapples.wordpress.com/2009/07/07/zero-factorial/ for more information!

Your program should prompt the user for a positive number (an integer) up to 15 and then use a while loop to print out the result.

Sample input:

Enter a number from 1 - 15: 5

Sample output:

The factorial of 5 - which is written as 5! is 120.

This program should be named as follows: lastname_firstname_assign3b.py (for example, shakespeare_will_assign3b.py)


Submit all programs by emailing them as attachments to the grader at: v002su2 [at] cs [dot] nyu [dot] edu

Notes about your program: