We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 550e76e commit c845a09Copy full SHA for c845a09
josephus.py
@@ -82,10 +82,15 @@ def append(self, target):
82
if __name__ == '__main__':
83
84
ring = RingSort()
85
- ring.append(Person("Jorn", 25))
86
- ring.append(Person("Tom", 30))
87
- ring.append(Person("Jerry", 35))
88
- ring.append(Person("Mike", 40))
+ f_txt = open("people.txt")
+ for line in f_txt:
+ if line.count(',') != 1:
+ raise IOError("格式错误")
89
+ line = line.strip('\n')
90
+ name = line.split(',')[0]
91
+ age = line.split(',')[1]
92
+ ring.append(Person(name, age))
93
+ f_txt.close()
94
95
try:
96
start = int(input("\nPlease input a starting position:"))
people.txt
@@ -0,0 +1,4 @@
1
+"Jorn", 25
2
+"Tom", 30
3
+"Jerry", 35
4
+"Mike", 40
0 commit comments