Finish the code so that it matches the comments. Click on the instructions table for more information.
Sample Output from the program above once completed
Enter value: 1
Enter value: 3
Enter value: 2
Enter Value: 10
Enter value: 145
Enter value: 23
Enter value:
Average = 30.6666666666666668
Read twelve temperature values from the user (one for each month), and display the number of the month with the highest temperature. You can get real data from http://worldclimate.com Example Death Valley data from Jan-Dec (in degrees Celsius):
18.2 22.6 26.4 31.1 36.6 42.2 45.7 44.5 40.2 33.1 24.2 17.6
In this case, the month with the highest temperature (45.7 degrees Celsius) is July, and the program should display 7.
. Click on the instructions table for more information.
Fill out the truth table below. Verify your answers by completing the code below.
Print 3 rows of 4 asterisks each
****
****
****
______________________________
2. Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4, the program should display
*
***
*****
*******
*****
***
*
______________________________
3. Prints a checkerboards pattern
* * *
* *
* * *
It is common to repeatedly read and process multiple groups of values. Write a program that can be used to compute the average exam grade for multiple students. Each student has the same number of exam grades.
Step 1 Understand the problem.
To compute the average exam grade for one student, we must enter and tally all of the grades for that student. This can be done with a loop. But we need to compute the average grade for multiple students. Thus, computing an individual student’s average grade must be repeated for each student in the course. This requires a nested loop. The inner loop will process the grades for one student and the outer loop will repeat the process for each student.
Step 2 Compute the average grade for one student.
The algorithm from Section 4.5.1 can be used to extract the grades and compute the average. The difference in this problem, however, is that we can read a fixed number of grades for each student instead of reading until a sentinel value is entered. Because we know how many grades need to be read, we can use a for loop with the range function:
Step 3 Repeat the process for each student.
Because we are computing the average exam grade for multiple students, we must repeat the task in Step 2 for each student. Because we do not know how many students there are, we will use a while loop with a sentinel value. But what should the sentinel be? For simplicity, it can be based on a simple yes or no question. After the user enters the grades for a student, we can prompt the user whether they wish to enter grades for another student:
A no response serves as the terminating condition. Thus, each time the user enters "Y" at the prompt, the loop will be executed again.
We will use a loop condition set to moreGrades == "Y", and initialize the loop variable to contain the string "Y". This allows the loop to be executed at least once so the user can enter the grades for the first student before being prompted for a yes or no response.
Sample OUTPUT:
How many exam grades does each student have? 3
Enter the exam grades.
Exam 1: 33
Exam 2: 73
Exam 3: 98
The average is 68.00
Enter exam grades for another student (Y/N)?