3 回答
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都放在一起,然后在下一行打印到控制台。
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 循环,每次都会打印玩家的姓名和得分。
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}
添加回答
举报