I've tried to make a program that will sort the results of a competition, by asking the user the number of competitors, then the name and score of each one.
It worked but now i have to make it recognize when two or more people get the same score (that is) they have the same position, and that the number of extra people on a position will be the number of position that will be omitted before it continues ranking the others. Here is what i have done, so far,
# Filename: result_sorter.py
# A Program that's sorts results
#
# Obasa Adegoke - 18/04/11(dd/mm/yy)
# This function allows the user to quit at any time in the program
def quitter(word):
""" Allows the user to quit at any time"""
if word.upper() == "Q":
quit()
else:
pass
def result_sorter():
play_again = 'yes'
while play_again == 'yes' or play_again == 'y':
# This line asks the user for the number of values
count = input("Number")
quitter(count)
count = int(count)
# Initialize the various lists to be used
name = []
score = []
sorting = []
# The Various names and respective scores are added to the lists
for i in range(count):
# this line accepts the name
temp1 = input("name")
quitter(temp1)
temp1 = str(temp1.title())
name.append(temp1)
# this line accepts the respective score
temp2 = input("score")
quitter(temp2)
temp2 = int(temp2)
score.append(temp2)
sorting.append(temp2)
# Scores are sorted in ascending order
sorting.sort()
print("\t Postion \t Name \t \t Score")
n = 1
k = count
while n!= count +1:
rank = sorting.pop(0)
index = int(score.index(rank))
name_sort = name[index]
print('\t {0} \t \t \t {1} \t \t {2}'.format(k, name_sort, rank))
n += 1
k -= 1
play_again = input("Do you want to sort again [y or n]")
play_again = play_again.lower()
print(" Result Sorter ".center(40, '*').center(70))
print(" version 1.0 ".center(40, '*').center(70))
print('To quit at anytime just type [q]'.center(70))
result_sorter()
print("copyright 2011".center(70))
Will love to know how i can make it do this, and also how i can make it print from top to bottom instead of bottom to top.
Thanks in advance.