Guest User

Untitled

a guest
Apr 7th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import operator
  2.  
  3. # Creates the User object
  4.  
  5. class User:
  6.     def __init__(self, user_name_peram, user_time_peram):
  7.         self.user_name = user_name_peram
  8.         self.user_time = float(user_time_peram)
  9.     def __str__(self):
  10.         return '[' + self.user_name + ', ' + str(self.user_time) + ']'
  11.     def __repr__(self):
  12.         return self.__str__()
  13.  
  14. # Inputs the users name and time
  15.  
  16. number_of_users = input('Enter the amount of users: ')
  17. counter = 0
  18. user_list = []
  19. while counter < int(number_of_users):
  20.     user_name = input('Enter user ' + str(counter + 1) + 's name: ')
  21.     user_time = input('Enter user ' + str(counter + 1) + 's time: ')
  22.     user_list.insert(counter, User(str(user_name), user_time))
  23.     counter += 1
  24.  
  25. # Sorts the users by their inputted time
  26.  
  27. user_list.sort(key=operator.attrgetter("user_time"), reverse=False)
  28.  
  29. # Calculates their flair
  30.  
  31. for i in reversed(range(len(user_list))):
  32.     if i is 0:
  33.         user_list[i].user_time = int(60 - user_list[i].user_time)
  34.     else:
  35.         user_list[i].user_time = int(60 - (user_list[i].user_time - user_list[i-1].user_time))
  36.  
  37. # Prints out the final result
  38.  
  39. print(user_list)
Advertisement
Add Comment
Please, Sign In to add comment