带有多个项目/请求的Python输入
我是在Python中编码的新手,我被困在以下内容:
我有一个作为输入的项目列表,该项目被空的newlines分开,例如:
input = """Andrew
Bob
Chanel
Danielle
Andrew Chanel 1 0
Danielle Bob 0 1
Andrew Danielle 0.5 0.5
Chanel Bob 1 0
Andrew Bob 0.5 0.5
Chanel Danielle"""
在此输入中,前4行应被视为名称在分类中的所有玩家中,称为结果
,带有名为名称的字符串。但是,在第一个空的新线之后,它给出了两个玩家的名称,其次是他们的结果(1 = win,0 =损失,均为0.5 = tie)。每个新线都是一场新的战斗,直到新的空的 newline是一轮。
我的问题:我需要具体说明哪些步骤:
- 所有参与者都是空的新线之前的第一部分?
- 之后的“段落”是回合?
- 名字是“ player_1”,第二个名称'player_2',第一个值'score_player_1'和第二个值'score_player_2'?
如果有人愿意帮助初学者,我很感激!
I'm new to coding in Python and I am stuck on the following:
I have a list of items as inputs, which is seperated by empty newlines, like so:
input = """Andrew
Bob
Chanel
Danielle
Andrew Chanel 1 0
Danielle Bob 0 1
Andrew Danielle 0.5 0.5
Chanel Bob 1 0
Andrew Bob 0.5 0.5
Chanel Danielle"""
In this input, the first 4 lines should be the seen as the names of all players in a classed called result
with a string called name. After the first empty newline, however, it gives the names of the two players followed by their result (1 = win, 0 = loss, both 0.5 = tie). Every newline is a new battle, and until a new empty newline is one round.
My question: what are the steps that I need to specify that:
- the first part before an empty newline is all players involved?
- the 'paragraphs' afterwards are rounds?
- that the first name is 'player_1', the second name 'player_2', the first value 'score_player_1' and the second value 'score_player_2'?
If anyone would be so kind to help a beginner out, I' appreciate it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下方式:
输出:
You can use this:
Output: