Guest User

Untitled

a guest
Jan 12th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. class User():
  2.     '''Creates a User class for a codewars style website'''
  3.  
  4.     def __init__(self):
  5.         self.ranks = [-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8]    #15
  6.         self.myprogress = 0
  7.         self.level = 0
  8.         self.myrank = self.ranks[self.level]
  9.  
  10.     def inc_progress(self, rank):
  11.         activityrank = self.ranks.index(rank)
  12.         myrank = self.level
  13.         difference = activityrank - myrank
  14.  
  15.         if self.level < 15:
  16.  
  17.             if rank not in self.ranks:
  18.                 raise Exception('Invalid rank')
  19.  
  20.             if difference > 0:                                              
  21.                 points = 10 * difference * difference
  22.                 self.myprogress += points
  23.  
  24.             elif difference == 0: self.myprogress += 3
  25.  
  26.             elif difference == -1: self.myprogress += 1
  27.            
  28.             if self.myprogress == 100:
  29.                 self.level += 1
  30.                 self.myrank = self.ranks[self.level]
  31.                 self.myprogress = 0
  32.  
  33.             if self.myprogress > 100:
  34.                 self.level += 1
  35.                 leftover = self.myprogress - 100
  36.                 self.myrank = self.ranks[self.level]
  37.                 self.myprogress = leftover
  38.  
  39.     def progress(self):
  40.         return self.myprogress
  41.  
  42.     def rank(self):
  43.         return self.ranks[self.level]
Advertisement
Add Comment
Please, Sign In to add comment