Home > other >  Help to look at
Help to look at

Time:11-20

Traceback (the most recent call last) :
The File "C://shiyansan python experiment. Py", line 68, in & lt; module>
Number, name, class_, t=item. The split (" ", 4)
ValueError: too many values to unpack (expected 4)
Error how to solve the

High number of class 1, 202001 zhang SAN: 89 English: 28 computer: 77
High number of class 1, 202002, li si: 90 English: 84 computer: 88
Fifty and high class one number: 202003 70 English: 90 computer: 67
Problem description: a written information about the students of class, instance attributes include: student id, name, gender, class, n course grades, requirements:
1) using the file read, create a class containing n students;
File storage format separated by Spaces such as: high class 1, 202001 bill number: 89 English: 28 computer: 77
2) n course grades use dictionary storage, support achievements recorded, modify and delete;
3) solving each student's grade average n door, and its average ranking, and according to the average scores ranking positive sequence output functions: student id, name, gender, age, n course grades, n course average, ranking,

The class Students:
Def __int__ (self, number, name, sex, age, class_, scores) :
Self. SetNumber (number)
Self. Elegantly-named setName (name)
Self. SetSex (sex)
Self. SetAge (age)
Self. SetClass (class_)
Self. SetScores (scores)
Self. SetAverage ()

Def setNumber (self, number) :
Self. __number=number

Def elegantly-named setName (self, name) :
The self. The __name=name

Def getName (self) :
Return the self. The __name

Def setSex (self, sex) :
Ran. __sex=sex

Def setAge (self, age) :
Self. __age=age

Def setClass (self, class_) :
Self. __class=class_

Def setScores (self, scores) :
Self. __scores=scores

Def changeScores (self, subject, scores) :
Self. __scores [subject]=int (scores)
Self. SetAverage ()

Def delScores (self) :
Del self. __scores

Def setAverage (self) :
Self. __average=sum (self) __scores) values ())/len (self. __scores)

Def getAverage (self) :
Return the self. __average

Def show (self) :
Print (student number: "", the self __number," name: ", the self. The __name, "gender", the self. The __sex, age: "", the self. __age)
For the key, the item in the self. __scores. The items () :
Print (" {0: & gt; 5} {1} {2: & lt; 5} ". The format ("="key, the item), end=" ")
Print (" % 8.2 f "% self. The __average, end=" \ t ")

Def show () :
S.s ort (key=lambda I: i.g etAverage ())
For the key item in enumerate (s) :
Item. The show ()
Print (len (s) - key)
Print (" \ n ")

Def the modify (name, subject, scores) :
For I in s:
If i.g etName ()==name:
I.c hangeScores (subject, scores)

S=[]

With the open (' C: \ \ \ \ python experiment text. TXT ', 'r', encoding="utf-8", errors='ignore') as f:
Messages=f.r eadlines ()
For the item in the messages:
Number, name, class_, t=item. The split (" ", 4)
T=list (t.s plit (" "))
Scores=dict ()
For I in t.i tems:
A, b, c=i.p artition ("=")
Scores of [a]=int (c)
Stu=Students (number, name, sex, age, scores)
S.a ppend (stu)

Show ()
The modify (" zhang ", "English", 77)
Show ()
The modify (" bill ", "computer", 90)
Show ()


  • Related