Jump to content

Choosing the highest percentage from a list (Python3)

lewdicrous
Spoiler

matchesWon1 = 0
matchesWon2 = 0
for y in range(1,2):
    infile = open("Team%d_Round%d.txt" %(x,y), "r")
    line = infile.readline()
    while line != "":
        scored = int((line.split()[1]))
        conceded = int((line.split()[2]))
        if scored > conceded:
            won = 1
        elif scored == conceded:
            won = 0
        elif scored < conceded:
            won = 0        
        scored = 0
        conceded = 0
        matchesWon1 += won
        line = infile.readline()
matchesWon1 = matchesWon1 / 4 * 100
for y in range(2,3):
    infile = open("Team%d_Round%d.txt" %(x,y), "r")
    line = infile.readline()
    while line != "":
        scored = int((line.split()[1]))
        conceded = int((line.split()[2]))
        if scored > conceded:
            won = 1
        elif scored == conceded:
            won = 0
        elif scored < conceded:
            won = 0        
        scored = 0
        conceded = 0
        matchesWon2 += won
        line = infile.readline()
matchesWon2 = matchesWon2 / 4 * 100
totalMatches = (matchesWon1 + matchesWon2)/2
outfile.write("%20.1f" %totalMatches)

5ac0df430f904_Screenshot-2018-4-1MicrosoftWord-HW3_updated_Abirdocx-HW3_SP18pdf.png.1781c19f8fe3b722d31f55de6b83776a.png

Hey, I'm trying to identify the highest percentage from the 5 that I have and from that information I want to identify the winning team.

The code I used to produce those percentages is available above, the program runs and produced the percentages that I need, I just don't know how to sieve through the data to get the highest number of the bunch, I tried several iterations of the code above to do so, but non of them worked(I also deleted them so I no longer have them for any referencing).

 

Thank you

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, lewdicrous said:

The code I used to produce those percentages is available above, the program runs and produced the percentages that I need, I just don't know how sieve through the data to get the highest number of the bunch, I tried several iterations of the code above to do so, but non of them worked(I also deleted them so I no longer have them for any referencing).

Keep this under your pillow: https://docs.python.org/3/library/functions.html

 

 

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

Storing your results in a collection, sorting the collection, getting the first/last entry.

 

Or, store a max variable (start it at 0), and every time you read a percentage, compare it to the max, if it is greater, it is the new max.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×