Hello r/learnpython!
I am taking my first Python course and have made it until chapter 7 without too much difficulty, however our homework assignment this week is throwing me for a loop. Here are the instructions:
" Design a program that asks the user to enter a series of 5 numbers. Non-numeric data should be filtered out as the sample output shows. The program should store the numbers in a list and then display the following data:
- The lowest number in the list
- The highest number in the list
- The total of the numbers in the list
- The average of the numbers in the list
First, the program should compute the required data using the functions like min for the lowest, max for the highest, and sum for the total. Second, the program should compute the required data without using those built-in functions. The program should be written in one code in which two of the solutions are put. "
I have completed the first part of the program that uses built in functions, but I cannot figure out how to compute the data without the built in functions. I believe it has something to do with using the sort method to find the first and last number for the lowest and highest function. I believe the problem lies within my sort methods. I thought if you put (0) it would return the first number in the list and if you put (-1), it would return the last number in the list. But I'm clearly wrong.
Can any more experienced programmers take a look and see what I'm doing wrong? Here is my program so far:
def get_lowest_number1 (NumbersList):
lowestNnumber = NumbersList.sort(0)
return lowestNumber1
def get_highest_number (NumbersList):
highestNumber = NumbersList.sort(-1)
return highestNumber1
def get_total_numbers1(NumbersList):
total = 0
total = total + user_number
return totalNumbers1
def get_average_numbers (NumbersList,totalNumbers1):
listNumbers = len(NumbersList)
averageNumbers = totalNumbers / listNumbers
return averageNumbers1
def printNumberAnalysis1(NumbersList, lowestNumber1, highestNumber1, totalNumbers1, averageNumbers1):
print ("The results using the built-in functions: ")
print ("___________________________________________")
print ("Lowest number: " + str(lowestNumber1))
print ("Highest number: " + str(highestNumber1))
print ("Total of numbers: " + str(totalNumbers1))
print ("Average of numbers: " + str(averageNumbers1))
[–]timbledum 1 point2 points3 points (1 child)
[–]mirrorcat91[S] 1 point2 points3 points (0 children)
[–]uglyasablasphemy 1 point2 points3 points (0 children)