Print Players With Their Score

507 views Asked by At

How can I print player’s names with their scores?

** (Player) Has (Score) Points

Here's My Code

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

There are 3 answers

1
Rahul Bohare On BEST ANSWER
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))

Output:

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 makes an iterator by aggregating elements from each of the iterables (here, we have players and score lists). Every element from players and score are taken together and then printed to the console on the next line.

0
dimay On

Use dict:

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)

Output

{'Akshit': 100,
 'Bhavya': 0,
 'Hem': 0,
 'Jay M': 0,
 'Jay Savla': 0,
 'Jayu': 0,
 'Miraj': 0,
 'PD': 0,
 'Pratik': 0,
 'Priyank': 0}
0
AudioBubble On

It is pretty easy, if I understood the question. I am pretty sure it is this:

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

All I did was add a for loop which prints the player's name and score each time.