Task 1 Task 2 Task 3
Random Name

Task 1

A teacher wants a program that allows her to enter the height of all her students and the program will display the tallest height entered.

Each day she has a different number of students.

Start with a variable called max_heightand assign it a small number, eg 0

Input the first student height and assign it to a variable, height.

While height is not equal to 0, repeat the following steps:

Compare height to max_height and if it is bigger assign height to max_height

Get the next height


Display the maximum height that was entered.


A Python programmer has followed the algorithm and developed a solution:

 

There are a few syntax errors. Correct the errors and then test the solution using this table of test data. Does it work properly?

height max_height output
- 0 -
160 160 max_height is now 160
130 - max_height is now 160
180 180 max_height is now 180
-300 - max_height is now 180
200 200 max_height is now 200
0 - You entered 0. The program is finished.
Random Name

Task 2

A scientific simulator generates random numbers between -5 and 5 inclusive. It counts how many numbers are negative and how many numbers are positive. It stops when the number of positive numbers or the number of negative numbers are greater than 5.

The program then displays the number of positive numbers and the number of negative numbers.

Write code for this scientific simulator.

Random Name

Task 3

A bank website has a program which tells customers how many years it will take for their investment to double if it earns a certain interest every year.

For example, if a customer has an investment of $10,000 and an annual interest rate of 5%, the program will calculate how many years it will take to double the investment to $20,000

An algorithm that will help to solve the problem is:

Start with a year value at 0

Get balance from user and store in variable called balance

Create the target balance which is 2*balance

Repeat the following steps while balance is less than target

Add 1 to the year value

Compute the interest as balance multiplied by 0.05

Add the interest to the balance


Display the number of years that it will take to double the initial investment balance and the final investment amount.


Follow this algorithm to write a program for the bank.