我完全不知道如何将列表更改为int。
#Creates a list which is populated by whole names and scores
whole_names = list()
scores = list()
for line in lines:
# Makes each word a seperate object
objects = line.split(" ")
# Joins the first and last name of every line and makes them
their own seperate objects
whole_names.append(" ".join(objects[0:2]))
# Makes the scores of every line an object
scores.append(objects[2:3])
rect = Rectangle(Point(2, y-50), Point(scores[0],y-25))
rect.setFill("darkgreen")
rect.draw(win)
问题是,Point(scores [0],y-25))不会填充,因为scores [0]是一个列表,而不是一个int,因此从技术上讲它不能是一个坐标,而是scores [0]的实际值该列表将是一些随机数,我不知道它将是多少,但实际上它将是整数。那么,如何将scores [0]转换为随机整数?我已经尝试过scores = int(scores),但是那根本没有用。
假设scores[0]
是这样的['10']
:
Point(int(scores[0][0]), y-25)
但是,这不是正确的解决方案。为了使它更好,请更改此行:
scores.append(objects[2:3])
哪个返回一个序列,对此:
scores.append(objects[2])
这将返回项目本身。这样,您只需要立即将其转换为整数即可:
Point(int(scores[0]), y-25)
希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句