Ad
Code
Diff
  • from random import choice
    
    class Student:
        
        assess_values = ['B-', 'B+', 'A-' 'A+']
        
        def __init__(self, first_name, last_name):
            self.first_name = first_name
            self.last_name = last_name
            self.grades = []
    
        @property
        def full_name(self):
            return f'{self.first_name} {self.last_name}'
    
        @property
        def email(self):
            return f'{self.first_name}{self.last_name[0]}@codewars.com'
    
        def add_grade(self, grade):
            self.grades.append(grade)
            
        @property
        def grade_average(self):
            if not self.grades:
                return 0
            return sum(self.grades) / len(self.grades)
        
        def assess(self):
            if not self.grades:
                return 'Ungraded'
            
            return self.assess_values[self.grade_average // 25]
            
                
        def add_random_grade(self):
            random_grade = choice(range(1, 11))
            self.grades.append(random_grade)
    
    • from random import choice
    • class Student:
    • assess_values = ['B-', 'B+', 'A-' 'A+']
    • def __init__(self, first_name, last_name):
    • self.first_name = first_name
    • self.last_name = last_name
    • self.grades = []
    • @property
    • def full_name(self):
    • return f'{self.first_name} {self.last_name}'
    • @property
    • def email(self):
    • return f'{self.first_name}{self.last_name[0]}@codewars.com'
    • def add_grade(self, grade):
    • self.grades.append(grade)
    • @property
    • def grade_average(self):
    • if not self.grades:
    • return 0
    • return sum(self.grades) / len(self.grades)
    • def assess(self):
    • if not self.grades:
    • return 'Ungraded'
    • avg = self.grade_average
    • if 0 <= avg <= 25:
    • return 'B-'
    • elif 25 < avg <= 50:
    • return 'B+'
    • elif 50 < avg <= 75:
    • return 'A-'
    • elif 75 < avg <= 100:
    • return 'A+'
    • return self.assess_values[self.grade_average // 25]
    • def add_random_grade(self):
    • random_grade = choice(range(1, 11))
    • self.grades.append(random_grade)
Code
Diff
  • unsigned long long div2(unsigned long long a) {
      return a >> 1;
    }
    • unsigned long long div2(unsigned long long a) {
    • return (a>=2) ? a/2 : 0;
    • return a >> 1;
    • }
Code
Diff
  • import math
    
    def shannon_entropy(s):
        symbols = list(s)
        unique_symbols = set(s)
        M = float(len(s))
        return -(sum([a * (math.log(a, 2)) for a in [symbols.count(x)/M for x in unique_symbols]]))
    • import math
    • def shannon_entropy(s):
    • symbols = list(s)
    • unique_symbols = set(s)
    • M = float(len(s))
    • entropy_list = []
    • for x in unique_symbols:
    • n_i = symbols.count(x)
    • P_i = n_i / M
    • entropy_i = P_i * (math.log(P_i, 2))
    • entropy_list.append(entropy_i)
    • sh_entropy = -(sum(entropy_list))
    • return sh_entropy
    • return -(sum([a * (math.log(a, 2)) for a in [symbols.count(x)/M for x in unique_symbols]]))
Fundamentals
Code
Diff
  • is_even=lambda n:int(not(n&True))
    • is_even=lambda n:n%((True*(True+True+True)+(True+True+True+True+True+True))//(True+True+True)-True)==True-True
    • is_even=lambda n:int(not(n&True))