Pythone topic


#1

In the workspace to your right, there is the outline of a function called grade_converter().

The purpose of this function is to take a number grade (1-100), defined by the variable grade, and to return the appropriate letter grade (A, B, C, D, or F).

Your task is to complete the function by creating appropriate if and elif statements that will compare the input grade with a number and then return a letter grade.

Your function should return the following letter grades

i can’t underestend above notice,phrhaps, i am either new in pyhthone or my english knowleg poor,
anybody here help to me…


#2
>>> marks = [60, 70, 80, 90, 101]
>>> grades = ['A','B','C','D','F']
>>> def cap(a):
	return filter(lambda x: x > a, marks)

>>> def get_letter_grade(n):
	return grades[len(cap(n)) - 1]

>>> get_letter_grade(59)
'F'
>>> get_letter_grade(60)
'D'
>>> get_letter_grade(70)
'C'
>>> get_letter_grade(80)
'B'
>>> get_letter_grade(90)
'A'
>>> get_letter_grade(100)
'A'
>>> 

This is not the solution that is expected by the exercise. It is a parallel. If-elif-else dynamics can play out in other ways.

>>> def get_letter_grade(n):
	return grades[len(filter(lambda x: x > n, marks))-1]

>>> get_letter_grade(59)
'F'
>>> get_letter_grade(60)
'D'
>>> get_letter_grade(70)
'C'
>>> get_letter_grade(80)
'B'
>>> get_letter_grade(90)
'A'
>>> get_letter_grade(100)
'A'
>>> 

#3

you are good persone and knowlegable persone’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’'
thank mr.


#4

Using if/elif/else what have you written for this? Is this an exercise on Codecademy or a homework assignment?


#5

it is exercise…i loves python


#7
def get_letter_grade(n):
    return 'ABCDF'[len(filter(lambda x: x > n, [60, 70, 80, 90, 101])) - 1]

When there is no outcome from the list, -1 is the outcome. Python slices the string from the right and finds F.

String of symbols versus list of gradients.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.