Intro to Computer Science
PA03
Working with Iteration
Code due to the Program Submission System on by 2/13 at 11:59pm
Introduction
This week we have been working with for and while loops. Let's see if
you understand this idea.
Notes and requirements:
- Make sure that you save your programs in the correctly named files
- Make sure that you are following the
proper policies
regarding code based homework
- Use meaningful variable names
- Use meaningful constants and names where appropriate and use proper style
- Your programs should ask for input in the exact order specified in the program specifications below.
Program 3.1 (5 points)
Create a program named money.py
- Let's create a program to demonstrate the effects of compound interest. A bank account, for example, may have its interest compounded every year: in this case, an account with $1000 initial principal and 20% interest per year would have a
balance of $1200 at the end of the first year, $1440 at the end of the second year, and so on.
- Write a program that:
- prompts the user for an amount of money to invest in the compounding account
- prompts the user for the interest rate per year
- prompts the user the number of years to compound
- uses a for loop to display the balance of the account for each year
- For example:
Program 3.2 (8 points)
Create a program named elevator.py
Have you ever noticed a sign like this on an elevator? Have you ever wondered if the people on the elevator were within the rated load?
In this problem you will write code that:
- asks the user for the rated load of the elevator
- starts with the assumption that the elevator is empty
- asks the user for the weight of the next passenger
- checks to see if that passenger can get on the elevator
- if they can, it says so, adds that weight to the current weight on the elevator and continues
- if that passenger will exceed the weight capacity it says so and then quits
- uses a while loop
- For example:
Program 3.3 (12 points)
Write a program called disarm.py
You are cleaning up in the Hall of Justice the morning after a huge Super Friends bash when a call comes in....
"This is the League of Doom!"
"We are going to blow up Aquaman with one billion pounds of TNT, if you don't give us a bazillion dollars!!!"
"..."
"..."
"..."
"We have Batman, too"
Now something has to be done, but there is no one around. It is all up to you.
Just then a batarang crashes through the window with a message from Batman:
The code to defuse the bomb is taking all the numbers of the geometric sequence
of 2 under a certain number N and multiplying them together.
- Ask for a defuse number N
- You must then use a loop (for or while??) to find the product of all the numbers in the geometric sequence of 2 less than N.
- The geometric sequence of 2 looks like this
1, 2, 4, 8, 16, 32, ... where you start with the number one and multiply the previous number by 2 to get the next number.
- For example:
Final Submission
Please submit all three programs to the Program Submission System by the due date and time.