Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 210

Finding largest value in a file and printing out value w name

$
0
0

I need to create a progtam that opens a file then reads the values inside the file and then prints out the name with the largest value.

The file contains the following info:

Juan,27Joe,16 Mike,29Roy,10

Now the code I have is as follows:

UserFile = input('enter file name')FileOpen = open(User File,'r')for lines in User File:    data = line.split(",")    name = data[0]    hrs = data[1]    hrs = int(hrs)    LHRS = 0    if hrs > LHRS:    LHRS = hrs    if LHRS == LHRS:        print('Person with largest hours is',name)

The following prints out:

Person with the largest hours is JuanPerson with the largest hours is Mike

How can I make it so it only prints out the true largest?


Viewing all articles
Browse latest Browse all 210


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>