Create a function called allButMax that expects no arguments. Instead, this func
ID: 3667544 • Letter: C
Question
Create a function called allButMax that expects no arguments. Instead, this function gets its input from the user at the keyboard. The function asks the user to enter a series of numbers greater than or equal to zero, one at a time. The user types end to indicate that there are no more numbers. The function computes the sum of all the values entered except for the maximum value in the series. (Think of this as dropping the highest homework score from a series of homework scores.) The function then both prints the sum and returns the sum. You may assume the user inputs are valid: they will either be a number greater than or equal to zero, or the string end. Here are some examples of how your function should behave:Explanation / Answer
def allButMax():
a = []
total = 0
while 1:
i = raw_input("Enter next number: ") #if raw_input is not working then try input("Enter next number: ")
if i=="end":
break;
else:
a.append(int(i))
if(a!=[]):
for i in a:
if i!=max(a):
total += i
print "The sum of all values except for the maximum value is ::" + str(total)
return total
print allButMax()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.