打印玩家的得分

如何打印玩家的姓名和分数?


**(玩家)拥有(得分)积分


这是我的代码👇🏼


#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")


print (players)

print (score)


holdtom
浏览 141回答 3
3回答

慕斯709654

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 pointsBhavya has 1 pointsHem has 2 pointsJayu has 3 pointsJay M has 4 pointsJay Savla has 5 pointsMiraj has 6 pointsPriyank has 7 pointsPD has 8 pointsPratik has 9 pointszip1通过聚合每个可迭代对象中的元素来创建迭代器(这里有players和score列表)。players和中的每个元素score都放在一起,然后在下一行打印到控制台。

精慕HU

如果我理解这个问题,这很容易。我很确定是这样的:#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 is: ")for i in range(11):    print(f"{players[i]} has {str(score[i])} points")我所做的只是添加一个 for 循环,每次都会打印玩家的姓名和得分。

江户川乱折腾

使用字典: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"] += 100print(dct)输出{'Akshit': 100, 'Bhavya': 0, 'Hem': 0, 'Jay M': 0, 'Jay Savla': 0, 'Jayu': 0, 'Miraj': 0, 'PD': 0, 'Pratik': 0, 'Priyank': 0}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python