为了账号安全,请及时绑定邮箱和手机立即绑定

打印玩家的得分

打印玩家的得分

holdtom 2023-12-12 14:44:27
如何打印玩家的姓名和分数?**(玩家)拥有(得分)积分这是我的代码👇🏼#python 3.7.1print ("Hello, Dcoder!")players = ["Akshit","Bhavya", "Hem", "Jayu", "Jay M", "Jay Savla", "Miraj", "Priyank", "PD", "Pratik"]score = [0,0,0,0,0,0,0,0,0,0]#0 = Akshit#1 = Bhavya#2 = Hem#3 = Jayu#4 = Jay M#5 = Jay Savla#6 = Miraj#7 = Priyank#8 = PD#9 = Pratik#10 = Shamuprint (players)print (score)players.append("Shamu")score. append(0)#RRvCSKscore[9] = (score[9]+100)score[7] = (score[7]+50)score[4] = (score[4]+30)print ("Result")print (players)print (score)
查看完整描述

3 回答

?
慕斯709654

TA贡献1840条经验 获得超5个赞

players = ["Akshit","Bhavya", "Hem", "Jayu", "Jay M", "Jay Savla", "Miraj", "Priyank", "PD", "Pratik"]

score = [0,1,2,3,4,5,6,7,8,9]

   

for player, sc in zip(players, score):

    print("{} has {} points".format(player, sc))

输出:


Akshit has 0 points

Bhavya has 1 points

Hem has 2 points

Jayu has 3 points

Jay M has 4 points

Jay Savla has 5 points

Miraj has 6 points

Priyank has 7 points

PD has 8 points

Pratik has 9 points

zip1通过聚合每个可迭代对象中的元素来创建迭代器(这里有players和score列表)。players和中的每个元素score都放在一起,然后在下一行打印到控制台。


查看完整回答
反对 回复 2023-12-12
?
精慕HU

TA贡献1845条经验 获得超8个赞

如果我理解这个问题,这很容易。我很确定是这样的:


#python 3.7.1

print ("Hello, Dcoder!")


players = ["Akshit","Bhavya", "Hem", "Jayu", "Jay M", "Jay Savla", "Miraj", "Priyank", "PD", "Pratik"]

score = [0,0,0,0,0,0,0,0,0,0]

#0 = Akshit

#1 = Bhavya

#2 = Hem

#3 = Jayu

#4 = Jay M

#5 = Jay Savla

#6 = Miraj

#7 = Priyank

#8 = PD

#9 = Pratik

#10 = Shamu


print(players)

print(score)


players.append("Shamu")

score.append(0)


#RRvCSK

score[9] = (score[9]+100)

score[7] = (score[7]+50)

score[4] = (score[4]+30)


print("Result is: ")


for i in range(11):

    print(f"{players[i]} has {str(score[i])} points")

我所做的只是添加一个 for 循环,每次都会打印玩家的姓名和得分。


查看完整回答
反对 回复 2023-12-12
?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

使用字典:


players = ["Akshit","Bhavya", "Hem", "Jayu", "Jay M", "Jay Savla", "Miraj", "Priyank", "PD", "Pratik"]

score = [0,0,0,0,0,0,0,0,0,0]


dct = {k: v for k, v in zip(players, score)}


dct["Akshit"] += 100

print(dct)

输出

{'Akshit': 100,

 'Bhavya': 0,

 'Hem': 0,

 'Jay M': 0,

 'Jay Savla': 0,

 'Jayu': 0,

 'Miraj': 0,

 'PD': 0,

 'Pratik': 0,

 'Priyank': 0}


查看完整回答
反对 回复 2023-12-12
  • 3 回答
  • 0 关注
  • 135 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信