I tried to make a program that gives me errors, but actually I can't put inputs. What I want to do is a function that receives a list of grades (Lists must be used), from 0 to 20, and a minimum passing grade min_grade, and returns the number of entries in the grades list with a value greater than or equal to min_grade. with a list, and another function with the media_approved:
The output I want will be something like this:
**approved([11.2, 13.5, 7.6, 4.4, 12.2, 12.1, 18.2, 9.4, 18.3, 12.33], 9.5)
6
approved([7.5, 3.3, 6.6, 6.4], 9.5)
0
average_passed([11.2, 13.5, 7.6, 4.4, 12.2, 12.1, 18.2, 9.4, 18.3, 12.3], 9.5)
13.9166
average_passed([7.5, 3.3, 6.6, 6.4], 9.5)
0**
The program I made is wrong, because it only calculates the average, it is badly programmed and does not have a part of what I said earlier.
Then goes the code:
def calc_average(s, scores):
scores = []
c = float(input())
def average(grades, c):
return sum(scores)/len(scores)
s = [11.2, 13.5, 7.6, 4.4, 12.2, 12.1, 18.2, 9.4, 18.3, 12.3]
print(average(s))
Can anyone help me, to change my code so that it is the same as the output I put earlier?
Thank you for your help.
CodePudding user response:
If you just want to calculate number of values greater than the given i/p. One of the potential solutions is:
def fn(input_list, target):
approved = []
for i in range(len(input_list)):
if input_list[i] >= target:
approved.append(input_list[i])
return len(approved)
This surely solves the first problem. I am not sure what media_approved means. Could you please elaborate on the same. Thank you, I hope this helps.
CodePudding user response:
def averaged_passed(s, c):
scores = []
for i in range(len(s)):
if(s[i]>=c):
scores.append(s[i])
try:
return sum(scores)/len(scores)
except:
return('No one passed')
def approved(s, c):
count =0
for i in range(len(s)):
if(s[i]>=c):
count=count 1
return count
c = float(input())
s = [7.5, 3.3, 6.6, 6.4]
print(averaged_passed(s,c))
print(approved(s,c))
