$30
CS160 Computer Science I
Lab 4:
Objective
Practice using event controlled loops
Practice using count controlled loops
Practice if, if/else statements
Practice with formatted output
You may do all parts in a single program. If you choose to do so have a print statement before
each part indicating which part of the assignment is executing, using something as simple as:
print (“Part A\n”)
Assignment
Part A
Write individual while loops to meet the following criteria. There is one input for these loops,
use the specified values. Print text before each loop, such as “Part 1” or “Part 2”, with a little
whitespace between each part to break up the output.
1)
Count from 0 to 25 (inclusive) by 5
2)
Count from 25 to 0 (inclusive, counting down by 1)
3)
Count from 0 to 10 (inclusive) by ½ - output one value per line and right justified with
one place after the decimal point.
Part B
Write a program that asks for the number of quiz scores to be entered. Then ask for that many
quiz scores. Once all of the quiz scores have been entered display the number of A’s, B’s, C’s,
D’s and F’s from the quiz. Use the basic 90, 80, 70, 60 criteria discussed in class to determine
each letter grade. Also display the class average from the quiz, with 2 places after the decimal
point.
For example:
Enter number of quiz scores: 6
Enter a quiz score: 70
Enter a quiz score: 90
Enter a quiz score: 65
Enter a quiz score: 84
Enter a quiz score: 92
Enter a quiz score: 60
Number of A’s: 2
Number of B’s: 1
Number of C’s: 1
Number of D’s: 2
Number of F’s: 0
Class average: 76.83Part C
Write a program that asks for integer values until the user enters 0. Once the user has finished
entering values, display the average of the positive values that were entered and the average of
the negative values that were entered. DO NOT make any assumptions regarding the data that
will be entered. If you are not able to calculate an average, state that no values of that type were
entered. Print out the average with 2 places after the decimal point.
For example:
Enter a value: 20
Enter a value: -20
Enter a value: 30
Enter a value: 0
Average of positive values: 25.00
Average of negative values: -20.00
Part D
Write a program that creates a table of Celsius to Fahrenheit conversions. The table should go
from 0 degrees Celsius to 100 degrees Celsius, counting by 5 degrees. Make sure each
Fahrenheit temperature it whole (integer) number, no decimal points in the output. Make sure
both columns of outputs are right justified.
To convert Celsius to Fahrenheit, use the formula F = C * 9/5 + 32.
For example:
Celsius Fahrenheit
0 32
5 41
...
95 203
100 21