W05 Code-along Activity: Lists of Numbers
Code-along Activity Overview
For this activity, you will code along with an instructor video that walks you through each step of the activity below. Make sure that you pause the video, or watch sections over if you need to, so that you are able to complete the entire activity.
Your instructor will post a link to the video in Microsoft Teams.
Program Requirements
Ask the user for a series of numbers, and append each one to a list. Stop when they enter 0
.
Once you have a list, have your program do the following:
Compute the sum, or total, of the numbers in the list.
Compute the average of the numbers in the list.
Find the maximum, or largest, number in the list.
The following shows the expected output:
Enter a list of numbers, type 0 when finished.
Enter number: 18
Enter number: 36
Enter number: 2
Enter number: 48
Enter number: 6
Enter number: 12
Enter number: 9
Enter number: 0
The sum is: 131
The average is: 18.714285714285715
The largest number is: 48
Enhancement
Once the basic functionality is working, allow the user to enter both both positive and negative numbers, then find the smallest positive number (the positive number that is closest to zero).
The following shows the expected output after completing the enhancement:
Enter a list of numbers, type 0 when finished.
Enter number: 3
Enter number: 5
Enter number: 7
Enter number: 3
Enter number: 2
Enter number: -1
Enter number: -4
Enter number: -8
Enter number: 0
The sum is: 7
The average is: 0.875
The largest number is: 7
The smallest positive number is: 2
Instructions
Find the video that your instructor has posted for this assignment and code along with them for each of the following steps.
Please work through the requirements in order with the instructor rather than jumping ahead to more complicated steps, to ensure that you are understanding the fundamental concepts.
Sample Solution
In addition to the instructor video, you can also view this sample solution. (This solution may be slightly different than the final code that you and your instructor created.)
Alternative Video Link
In addition to the link that your instructor posted, you are also welcome to watch the following code walkthrough or use its transcript:
- Lists of Numbers Code-along Video (24 minutes)
Submission
Please pause and re-watch any sections of the instructor video necessary until you have completed the entire activity and your program runs the same as the instructor's. When you are finished:
- Return to Canvas to take the quiz.
Up Next
- W05 Project: Shopping Cart
Other Links:
- Return to: Week Overview | Course Home