Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- # Creates the User object
- class User:
- def __init__(self, user_name_peram, user_time_peram):
- self.user_name = user_name_peram
- self.user_time = float(user_time_peram)
- def __str__(self):
- return '[' + self.user_name + ', ' + str(self.user_time) + ']'
- def __repr__(self):
- return self.__str__()
- # Inputs the users name and time
- number_of_users = input('Enter the amount of users: ')
- counter = 0
- user_list = []
- while counter < int(number_of_users):
- user_name = input('Enter user ' + str(counter + 1) + 's name: ')
- user_time = input('Enter user ' + str(counter + 1) + 's time: ')
- user_list.insert(counter, User(str(user_name), user_time))
- counter += 1
- # Sorts the users by their inputted time
- user_list.sort(key=operator.attrgetter("user_time"), reverse=False)
- # Calculates their flair
- for i in reversed(range(len(user_list))):
- if i is 0:
- user_list[i].user_time = int(60 - user_list[i].user_time)
- else:
- user_list[i].user_time = int(60 - (user_list[i].user_time - user_list[i-1].user_time))
- # Prints out the final result
- print(user_list)
Advertisement
Add Comment
Please, Sign In to add comment