I tried to make a basic algorithm and it works however, the sum and average print out twice, and the small and largest digit sometimes prints twice or doesn't print.
revenues_list = []
answer = input("Do you have data to record? ")
while (answer != "no"):
try:
earnings = float(input("How much was earned? "))
except:
print("You need to give a number with digits.")
answer = input("Do you have more data to record? ")
revenues_list.append(earnings)
print(revenues_list)
#make a function that finds the maximun value of the list
def getMaximun(L):
myMaximun= L[0]
for element in revenues_list:
if(myMaximun > element):
myMaximun = element
print("Your largest element is: " + str(myMaximun))
#make a function that finds the minimun value of the list
def getMinimun(L):
myMinimun= L[0]
for element in revenues_list:
if(myMinimun < element):
myMinimun = element
print("Your smallest element is: " + str(myMinimun))
#make a function that finds the average of the list
def getAverage(L):
sum = 0
for element in revenues_list:
sum = sum + element
average = sum/len(L)
print("Your sum revenue is: " + str(sum) + "\n" + "Your average revenue is: " + str(average))
getMaximun(revenues_list)
getMinimun(revenues_list)
getAverage(revenues_list)
printis in the loop ...returnand return the value to the caller. So, at the end of eachget...function, usereturn myResultinstead ofprint(myresult)(at the correct location, see existing answer), and where you call the function useprint(getXxx(revenues_list)), or use an intermediary if you want.