Write a program that uses a while loop to store goals and assists for Lightning players in a text file. The program should prompt the user for player names, goals, and assists as shown below. Enter data for at least five players. You can make up the names and data. Each datum should be stored on its own line in the file. This is for Python. I have attached the program6_1 that I have so far, but it only allows me to enter one name before crashing. def main(): i = 0
Write a
This is for Python. I have attached the program6_1 that I have so far, but it only allows me to enter one name before crashing.
def main():
i = 0
with open("test.txt", 'w') as f:
f.writelines("{:<10s}{:<10s}{:<10s}\n".format("Name", "Goals", "Assist"))
while i < 5:
name = input("\nEnter Player Name: ")
goals = int(input("Enter goals: "))
assist = int(input("Enter Assist: "))
f.writelines("{:<10s}{:<10d}{:<10d}\n".format(name, goals, assist))
i += 1
main()
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images