Homework 5 (due 20 February):Problem A: In mathematics, the notation n! represents the factorial of the nonnegative
integer n. The factorial of n is the product of all the nonnegative integers from 1 to n.
For example,
4! = 1.2.3.4. = 24
and
7! = 1.2.3.4.5.6.7 = 5040.
Write a program that lets the user enter a nonnegative integer then uses a loop to
calculate the factorial of that number. Display the factorial.
Problem B: Write a program that calculates the amount of money a person would earn
over a period of time if his or her salary is one penny the first day, two pennies the
second day, and continues to double each day. The program should ask the user for the
number of days. Display a table showing what the salary was for each day, then show
the total pay at the end of the period. The output should be displayed in a dollar
amount, not the number of pennies.
Problem C: Write a program that predicts the approximate size of a population of
organisms. The application should use text boxes to allow the user to enter the starting
number of organisms, the average daily population increase (as a percentage), and the
number of days the organisms will be left to multiply. For example, assume the user
enters the following values:
Starting number of organisms: 2
Average daily increase: 30%
Number of days to multiply: 10
The program should display the following table of data:
Day Population
2
2.6
3.38
4.394
5.7122
7.42586
9.653619
12.5497
16.31462
21.209
1
2
3
4
5
6
7
8
9
10
Homework 7 (due 3 March): Problem A: Write a function named max that accepts
two float values as arguments and returns the larger of the two values. For instance, if
1.3 and 3.9 are given, then it should return 3.9.
Problem B: (Rock, paper, scissors game) Write a program that lets the user play rock,
paper, scissors against the computer. Here is how it should work:
1. A random number between 1 and 3 should be generated at the start of the game. If
that number is 1, then the computer will play “rock”, if it is 2, then the computer will
play “paper”, and if it is 3 then the computer will play “scissors” (but do not display
this choice to the user).
3. The computer’s choice is shown after the user enters their choice.
4. The winner is selected by the following rules:
• if one chooses rock and the other scissors, the player choosing rock wins
• if one chooses scissors and the other chooses paper, the play choosing scissors wins
• if one chooses paper and the other chooses rock, the player choosing paper wins
• if both players choose the same, then the game is a tie and must be played again
5. The entire gameplay steps 1 through 3 should be built into a function named
play_game ()
. Based on step 4, the function should either print the winner and return a 1 OR it
should print “There is a tie” and return a 0. Returning a zero should cause a loop
running the game function to be run again until a 1 is returned. (hint: something like
while gamereturn!=1:
gamereturn=play_game ()
is what you want to do here)