Demo entry 6783345

johndripper

   

Submitted by anonymous on Feb 09, 2019 at 14:09
Language: ANTLR With Python Target. Code size: 1.4 kB.

team_dict ={}
winningList=[]
winningTeam=[]


def inputNumber(userInput):	
	while True:
		try:
			_value_=int(input(userInput))
		except:
			print("Please enter integer value(s)")
			continue
		else:
			return _value_
			break

numofTeams=inputNumber("Insert Number of Teams: ")

for x in range(numofTeams):
	teamName=input('Team Name: ')
	winLossList=[]
	#wins = int(input('Wins: '))
	wins = inputNumber('Wins: ')
	winningList.append(wins)
	#losses=int(input('Losses: '))
	losses = inputNumber('Losses: ')
	if(wins>losses):
		winningTeam.append(teamName)
	
	winLossList.append(wins)
	winLossList.append(losses)
	team_dict[teamName] = winLossList

print("\nEntered dictionary: ", team_dict)
print('List of wins of all teams: ', winningList)
print("List of all teams that have winning records: ", winningTeam)


while True:
	
	team=input("\nEnter a team name to know the winning percentage: ")
	if team in team_dict:
		total_number_of_matches=sum(team_dict[team])								
		print('Total Number of Matches played by ', team,' : ', total_number_of_matches)
		winsVsLoss=team_dict[team]													
		winning_percentage=(float(winsVsLoss[0])/float(total_number_of_matches))*100 # winsVsLoss[0] = 1st element of the list which is the wins of the team
		print("Winning percentage of ",team," : ",winning_percentage,"%")
	else:
		print("the key doesnt exist")
		

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).