I'm just a newbie to Python so my code probably doesn't look that good, but it works fine except one thing. If for example my listofnumberofpancakes is [1,2,3,3] and I'm looking for the max which is 3, it will print out index 2 and 3. But, later on in my code, when I want to print the values of my listofnames of index 2 and 3, it will print person2 ate the most pancakes and on a new line person3 ate the most pancakes, how can I put that together? Like: person2 and person3 ate the most pancakes. Here's my code:
pancakes
listofnames = []
listofnumberofpancakes = []
print "I will ask you ten times to give in the name of a person and how many pancakes he/she ate."
for count in range(0,10):
name = str(raw_input("What's the name of the person?"))
numberofpancakes = int(raw_input("And how many pancakes did he/she eat?"))
listofnames.append(name)
listofnumberofpancakes.append(numberofpancakes)
print "\n"
print "The max of pancakes eaten by a person was: ", max(listofnumberofpancakes)
print "The minimum of pancakes eaten by a person was: ", min(listofnumberofpancakes)
for i, j in enumerate(listofnumberofpancakes):
if j == max(listofnumberofpancakes):
print listofnames[i], "ate the most pancakes"
for lala, a in enumerate(listofnumberofpancakes):
if a == min(listofnumberofpancakes):
print listofnames[lala], "ate the least pancakes"
print listofnumberofpancakes
Example of an output:
The max of pancakes eaten by a person was: 9
The minimum of pancakes eaten by a person was: 1
emma ate the most pancakes
tina ate the most pancakes
ina ate the least pancakes
[3, 3, 2, 5, 9, 9, 2, 1, 8, 4]