First, based on the input of all subjects whether the target student achievement statistics
1 (background: Enter the number of students, as well as individual students' language, mathematics, English, history score four subjects, and if the total score is less than 240 , the result of non-compliance, otherwise qualified success) 2 3 # Coding = UTF-8 4 the n-= int (the iNPUT ( ' Please enter the number of student: ' )) # enter the number of students, and converted to an integer 5 Print ( ' - ' * 50 ) # print the dividing line 6 Subjects = ( ' language ' , ' mathematics ' , ' English ' , ' history ' ) # create disciplines tuple 7 the Data ={#} Create Data Dictionary, for storing student name + score . 8 for i in Range (. 1,. 1 n-+ ): # student input element number i of the recording, the control cycles . 9 name = INPUT ( ' Please enter {} students name: ' .format (i)) # define a variable name, the name of the student receives an input 10 i + # =. 1 student each input element i is incremented. 1 . 11 Marks = [] # creating list Marks, each student records the four subjects scores 12 for x in subjects: # element x traverse disciplinary record 13 marks.append (int (the INPUT ( 'Enter the results {}: ' .format (X)))) # receiving input results, converted to an integer, and marks added to the list of 14 data [name] = marks # added to the dictionary data of the present cycle and name Marks 15 Print () new line # 16 Print ( ' - ' * 50 ) dividing a print line # . 17 for X, Y in data.items (): # traversing the dictionary data 18 is Print (X, Y) traverse the dictionary contents Print # 19 total =sum (y) # define variables total, using the sum () of the total score is calculated for each student 20 is Print ( ' {}} total score {, ' .format (X, Total), End = '' ) Print # Student total score of 21 is IF total <240 : If the total score is less than # 240, the student performance is not up to 22 is Print ( ' {} substandard results ' .format (X)) 23 is the else : # otherwise qualified success 24 Print ( ' {} the results qualified ' .format (the X-))
the results:
Knowledge points:
- # Tuple tuple number comma separated values. Tuples are immutable, this does not remove or add or edit any value in a tuple.
-
A dictionary is unordered dictionary # key-value pairs (
key:value
) set of keys within the same dictionary must be different from each other. Use a pair of braces{}
creates an empty dictionary. Can be used del keywords to deleteAny given key-value pairs, such as del data [ 'John Doe']; to traverse a dictionary, a dictionary of the
items()
method, as embodied examples. - List # list enclosed within brackets beginning of the end, you can store different data types of variable data structures. As a = [1,2.2, 'Hello' , True, [1,2,3]]. List of related methods: append (), end of the list as the additive element; INSERT (), the data is inserted to a position of the list, such as insert (2,1), 2 table index i.e. additive elements 1 position; COUNT () , the number of elements in the list of queries, such as count (1); remove () , the list of elements removed; reverse (), reversing the entire list, such as a = [1,2,3], after inversion becomes a = [3,2,1]; extend ( ), a list of all the elements of the list to the end of another, such as a = [1,2], b = [3,4], a.extend (b ), then a = [1,2,3,4]; sort ( ), to sort the list of elements, provided that the list element may be compared; del keywords, using del a [-1] to delete the list of elements, exemplified deleted elements of a list at the end.