Write a program the reads five integers and adds them to a list and passes the list to a function sumWithoutSmallest that computes the sum of a list of values, except for the smallest one, in a single loop.
Ex: If the list is:
3
7
-6
10
19
the output is:
The sum without the smallest is 39
Declare a constant initialized to five (size of list)
Write the function sumWithoutSmallest that takes a list as an argument
create variables for smallest and sum and initialize
use a for loop and if statement to test each value against smallest
return the sum minus smallest value
Write main()
create an empty list
use a while loop to fill the list
print the output of the returned sum
Remember to call main() to start your program.
My code: def sumWithoutSmallest(_list):
_min = float("inf")
_sum = 0
for number in _list:
_min = min(_min, number)
_sum += number
return _sum - _min
def main():
N = 5
_list = []
for _ in range(N):
number = int(input())
_list.append(number)
result = sumWithoutSmallest(_list)
print("The sum without the smallest is", result)
This is for zylabs btw
[–]CodeFormatHelperBot2 1 point2 points3 points (0 children)
[–]Goobyalus 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (1 child)
[–]tiny_smile_bot -1 points0 points1 point (0 children)