Question

Python, After a game has ended, write or save all the player names and scores to...

Python,
After a game has ended, write or save all the player names and scores to a file.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
from random import randint

n = int(input('How many players are playing the game? '))

names = []
scores = []
for i in range(n):
    names.append(input('Enter name of player ' + str(i+1) + ': '))
    scores.append(0)
while True:
    value = randint(1, 30)
    for i in range(n):
        guess = int(input(names[i] + ", Enter your guess: "))
        if guess == value:
            print(names[i] + ", You guessed it correctly. You are the WINNER of this round!")
            scores[i] += 1
            break
    choice = input('Do you want to continue(y or n): ')
    if choice == 'n':
        break

filename = input('Enter output file name: ')
with open(filename, 'w') as f:
    f.write('Name\tScore\n')
    for i in range(len(names)):
        f.write(names[i] + '\t' + str(scores[i]) + '\n')
Add a comment
Know the answer?
Add Answer to:
Python, After a game has ended, write or save all the player names and scores to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT