LESSON 05 – FOR LOOPS II

 


WORK

TASK

 

Try this practice quiz before attempting the programs below.

 

PROGRAM 1 – A+ STUDENT

 

Create a list that contains 8 marks (numbers between 0 and 100).  Use a for loop to process the list and count the number of marks that are 80 or over.  At the end, you should ouput a message such as You have 4 As! where 4 is the amount of marks at or above 80.

 

PROGRAM 2 – AVERAGE

 

Alter Program 1 to calculate and output the average of the 8 marks in the list.

 

PROGRAM 3 – DIGIT DIGIT DIG IT!

Write the program that immediately gets two numbers from the user.  The first number, which we will call n, is the digit.  The second number, which we will call r, is the number of repeating terms.

The program then calculates n + nn + nnn + … depending on the number of repetitions.  For 2 repetitions, the program calculate n + nn.  But for 4 repetitions, it does n + nn + nnn + nnnn.

 

SAMPLE IO

7

3

861

 

Explanation

The digit is 7.  The value of repetitions is 3.  So 7 + 77 + 777 = 861

SAMPLE IO
3
1

3

Explanation
The digit is three with only one repetition.  So the answer is 3.

 

Got extra time?

Try also adding the addition to the output.  So for the first Sample IO, the output would be:

 

            7 + 77 + 777 = 861