Below is my program, but It isn\'t working. Also are the instructions. Averaging
ID: 3556104 • Letter: B
Question
Below is my program, but It isn't working. Also are the instructions.
Averaging Lists
Some people would be interested in finding out the average and median of numbers in the list.
The median is the exact middle value in a set of values. You should show the median and the name of the student in the median. You should also display the average of all the grades.
Hint: You can copy the list of grades to then find the median. You do not want to mess with the original data.
Sorting the list
Most rosters we look at are alphabetical. The list given is not sorted. You should the list and match the grades with the alphabetically sorted list. There are a few sorting function options in the "Searching and Sorting Algorithms" module. Use the arrayAlgorithms file for assistance. Do not use the sort function.
Searching the list
After sorting the array, provide users the opportunity to search for a name. The user will see the name of the student and the associated grade if the name is found or display the message "Student not found".
Names = ['Turner', 'Philips', 'Stevenson', 'Jones', 'Gonzalez', 'Whitaker', 'Bruner', 'Webster', 'Foster', 'Anderson', 'Klein', 'Connors', 'Rivers', 'Wilson', 'Duncan']
Grades = [94, 82, 87, 78, 65, 90, 85, 97, 70, 100, 57, 88, 73, 92, 84]
def average(g_list):
sum = 0
n = len(g_list)
for i in range(n):
sum = sum + g_list[i]
return sum/float(n)
avg = average(Grades)
print (avg)
def median(g_list):
lst = g_list
even = (0 if len(lst) % 2 else 1) + 1
half = (len(lst) - 1) / 2
return sum(sorted(lst)[half:half + even]) / float(even)
median1 = median(Grades)
print (median1)
def sort(n_list, g_list):
length = len(n_list) - 1
sorted = False
while not sorted:
sorted = True
for i in range(length):
if n_list[i] > n_list[i+1]:
sorted = False
n_list[i], n_list[i+1] = n_list[i+1], n_list[i]
g_list[i], g_list[i+1] = g_list[i+1], g_list[i]
sort(Names, Grades)
print (Names)
print (Grades)
def binarySearch(n_list, g_list, name):
min = 0
max = len(n_list) - 1
while True:
if max < min:
return 'Student not found'
m = (min + max) // 2
if n_list[m] < name:
min = m + 1
elif n_list[m] > name:
max = m - 1
else:
return g_list[m]
g = binarySearch(Names, Grades, 'Philips')
print (g)
g = binarySearch(Names, Grades, 'BlackJack')
print (g)
Explanation / Answer
I ran your your code, and its working for me. Its Giving the following output :
>>>
82.8
85.0
['Anderson', 'Bruner', 'Connors', 'Duncan', 'Foster', 'Gonzalez', 'Jones', 'Klein', 'Philips', 'Rivers', 'Stevenson', 'Turner', 'Webster', 'Whitaker', 'Wilson']
[100, 85, 88, 84, 70, 65, 78, 57, 82, 73, 87, 94, 97, 90, 92]
82
Student not found
>>>
I verified eevry output and they are correct.
what is the error you are getting ?? (maybe its not working at your end due to some indentation error)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.