Advertisement
crosby0486

BK Multi-Cat LB Python Code

Jan 16th, 2021
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import datetime
  2. import math
  3. import operator
  4.  
  5. # dictionary containing all users points
  6. users = {
  7. }
  8.  
  9. # WR's
  10. wr_hundo = 7059
  11. wr_any = 3581
  12. wr_norba = 3856
  13. wr_cheat = 3554
  14. wr_nodog = 4282
  15. wr_trotless = 489
  16.  
  17. # Prompts, Data Collection
  18. while True:
  19.     # Resets to points to default (0)
  20.     points = {
  21.         "hundo": 0,
  22.         "any": 0,
  23.         "norba": 0,
  24.         "cheat": 0,
  25.         "nodog": 0,
  26.         "trotless": 0,
  27.     }
  28.  
  29.     #Username
  30.     name = input('Enter Username: ')
  31.  
  32.     # function for collecting user info about a given category
  33.     def time(cat,wr,weight):
  34.         while True:
  35.             a = input('Does ' + name + ' have a BK '+cat+' PB? (Y/N) ').lower()
  36.             if a == 'y':
  37.                 string = input('What is ' + name + '\'s BK '+cat+' time? (HH:MM:SS) ')
  38.                 try:
  39.                     date_time = datetime.datetime.strptime(string, "%H:%M:%S")
  40.                     timedelta = date_time - datetime.datetime(1900, 1, 1)
  41.                     sec = timedelta.total_seconds()
  42.                     points[cat] = math.ceil(max(weight*(((wr*1.5 - sec)**2)/(wr*0.5)**2),0))
  43.                     break
  44.                 except ValueError:
  45.                     print('Please use the format: HH:MM:SS')
  46.                     continue
  47.             elif a == 'n':
  48.                 break
  49.             else:
  50.                 print('Please enter either "Y" or "N".')
  51.                 continue
  52.  
  53.     # calls previous function for each category; # represents weight
  54.     time("hundo",wr_hundo,600)
  55.     time("any",wr_any,300)
  56.     time("norba",wr_norba,200)
  57.     time("cheat",wr_cheat,100)
  58.     time("nodog",wr_nodog,100)
  59.     time("trotless",wr_trotless,100)
  60.  
  61.     # totals user's points, prints data, & adds key/value to 'users' dictionary
  62.     pts_total = sum(points.values())
  63.  
  64.     print(name,'\'s Points: ')
  65.     for key, value in points.items():
  66.       print(f"{key}: {value}, ", end="")
  67.     print("")
  68.  
  69.     print('Total: ',pts_total)
  70.  
  71.     users[name]=pts_total
  72.  
  73.     # prompt to add more users
  74.     while True:
  75.         x = input('Would you like to enter another username? (Y/N) ').lower()
  76.         if x=='y' or x=='n':
  77.             break
  78.         else:
  79.             print('Please enter either "Y" or "N".')
  80.             continue
  81.     if x=='n':
  82.         break
  83.  
  84. # sorts users based on points and prints
  85. sorted_users = sorted(users.items(), key=operator.itemgetter(1),reverse=True)
  86.  
  87. print(*sorted_users, sep='\n')
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement