Now there are the following requirements:
" to achieve such a function: a class of students to make some assessment, the rules are: one : [0-60) --F-double : [60-70)- -D Three: [ 70-80) --C four : [80-90 ]--B five: [90-100] --A ' "
The bisect in Python can achieve the above requirements
Operating effect:
#python bisect "To achieve such a function: to a class of students to make some assessment, the rules are: one: [0-60)--F: [60-70)--D Three: [70- ---C four: [80-90]--B five: [90-100]--a ######################################### you'll probably think of using: if .... else ... Or think of using: Switch ... (Java) ########################################## the following two methods are not used to achieve this function "' Import randomimport bisectdef Create_studen T_scores (n): #根据学生人数n, create student score if n >= 0:scores = [] for x in range (n): Scores.append (ran Dom.randrange (0, 101, 1)) Return scores else:print (' The number should be greater than 0! ') def grade (score, breakpoints = [Max, Max, Max], grades = ' FDCBA '): i = Bisect.bisect (breakpoints, score) return GRA Des[i]def Main (): Student_scores = Create_student_scores (Ten) student_results = [Grade (score) for score in STUDENT_SC Ores] Print (' Student score: {}\n rating result: {} '. Format (student_scores, student_results)) if __name__ = = ' __main__ ': Main ()