Programming problem: the existing 100 student achievement, achievement as an integer (0-100), for rank statistics the number of each level and output statistics results: one is divided into five grades, more than 90 points for the best; 80 ~ 89 was divided into good; 70 ~ 79 were divided into medium; 60 ~ 69 divided into pass; Below 60 points for the fail,
Implementation steps are as follows:
1, the random Numbers produced 100 student achievement and put them in a list
2, the achievements of the list of statistics, statistical results in the dictionary (function)
Among them to implement a function to convert a single score to rank
3, the output the results in the dictionary
CodePudding user response:
refer to the original poster HDBDXBC response: programming: the existing 100 grades, scores as an integer (0-100), for rank statistics the number of each level and output statistics results: one is divided into five grades, more than 90 points for the best; 80 ~ 89 was divided into good; 70 ~ 79 were divided into medium; 60 ~ 69 divided into pass; Below 60 points for the fail, Implementation steps are as follows: 1, the random Numbers produced 100 student achievement and put them in a list 2, the achievements of the list of statistics, statistical results in the dictionary (function) Among them to implement a function to convert a single score to rank 3, output the results in the dictionary Import the random The from the collections import Counter Def do_level (study) : If study & gt;=90: Return "good" Elif 80 & lt;=study & lt;=89: Return "good" Elif 70 & lt;=study & lt;=79: Return "medium" Elif 60 & lt;=study & lt;=69: Return "pass" Elif study & lt; 60: Return "fail" Def get_all_study_info () : Class_int_list=list () Class_study_list=list () For I in range (100) : Stud_class=random. Randint (0100) Class_int_list. Append (stud_class) Print (" this is the list of student performance output: {} ". The format (class_int_list)) For I in class_int_list: Study=do_level (I) Class_study_list. Append (study) # print (class_study_list) Return class_study_list Def the main () : Class_study_list=get_all_study_info () Study (class_study_list)=Counter # statistical functions, the list of statistics the number of occurrences of each element in the Print (" this is the student achievement dictionary output: {} ". The format (dict (study)) If __name__=="__main__ ': The main () CodePudding user response:
reference 1st floor MuSa xiaoxiang reply: Quote: refer to the original poster HDBDXBC response: Programming problem: the existing 100 student achievement, achievement as an integer (0-100), for rank statistics the number of each level and output statistics results: one is divided into five grades, more than 90 points for the best; 80 ~ 89 was divided into good; 70 ~ 79 were divided into medium; 60 ~ 69 divided into pass; Below 60 points for the fail, Implementation steps are as follows: 1, the random Numbers produced 100 student achievement and put them in a list 2, the achievements of the list of statistics, statistical results in the dictionary (function) Among them to implement a function to convert a single score to rank 3, output the results in the dictionary Import the random The from the collections import Counter Def do_level (study) : If study & gt;=90: Return "good" Elif 80 & lt;=study & lt;=89: Return "good" Elif 70 & lt;=study & lt;=79: Return "medium" Elif 60 & lt;=study & lt;=69: Return "pass" Elif study & lt; 60: Return "fail" Def get_all_study_info () : Class_int_list=list () Class_study_list=list () For I in range (100) : Stud_class=random. Randint (0100) Class_int_list. Append (stud_class) Print (" this is the list of student performance output: {} ". The format (class_int_list)) For I in class_int_list: Study=do_level (I) Class_study_list. Append (study) # print (class_study_list) Return class_study_list Def the main () : Class_study_list=get_all_study_info () Study (class_study_list)=Counter # statistical functions, the list of statistics the number of occurrences of each element in the Print (" this is the student achievement dictionary output: {} ". The format (dict (study)) If __name__=="__main__ ': The main () Thank you???????? ! CodePudding user response:
Will not stick