In: Computer Science
Implement a simple football league system that will record and display the league according to the following specification: Each Team will have the following attributes: • Name • Games played • Games won • Games lost • Games drawn (this should be a calculated value) • Points (calculate using 3 points for a win and 1 for a draw)
Your program must include the following functionality:
For this question,you did not mention in which language you want a code .so, I write a code in Python language :-
ch='y'
while(ch!='Q'):
display=str(input("\nEnter 'N' for new
record\n'D' for display information\n'Q' to Quit:"))
if display=='N': # if user enter 'N' for add new
record
#now get attributes: Name , Games played ,Games won , Games
lost
name = str(input ("Enter a Team Name
:"))
gameplayed= int (input("Enter a Total Game played :"))
gamewin = int (input("Enter a Total Game Win:"))
gamelost=int (input("Enter a Total Game lost:"))
gamesdrawn=gameplayed-gamewin-gamelost
#calculate gamesdrawn
points=3*gamewin+1*gamesdrawn
#calculate points
file1=open("game.txt",
"a") #
open game.txt file here 'a' for add data to end of the file
# now write all attributes into file
file1.writelines(name+"\t\t\t")
file1.writelines(str(gameplayed)+"\t\t")
file1.writelines(str(gamewin)+"\t\t")
file1.writelines(str(gamelost)+"\t\t")
file1.writelines(str(gamesdrawn)+"\t\t")
file1.writelines(str(points)+"\n")
file1.close() #close the file
elif display=='Q': #if user enter
'Q' then quit
break
elif display=='D': #if user enter 'D' then
display information
file1=open("game.txt", "r") #open file for read
Lines = file1.readlines() #get all lines from game.txt file
print("name\t\t\t"+"gameplayed\t"+"gamewin\t\t"+"gamelost\t"+"gamesdrawn\t"+"points")
for line in Lines:
#We can iterate over the list and strip the
newline '\n' character using strip()
function
print(line.strip()) #print all record line by line,
file1.close() #close file
Screenshot of code, game.txt file and output :-