Ad

This currently does 8 extra steps, performs the same task :3

Edit: oops left a print

Code
Diff
  • import math
    
    def takeYourAge(age):
        try:
            age *= 3
            age %= 1.233
            age += math.pi
            age = math.log2(age)
            age **= 10 ** 2
            age -= math.e
            t_age = math.log(age)
            age = t_age / age
            age += 9
            age **= 0.5
            age = ((age * 7) - (5 * age)) / 2 + age / 2
            age += (math.sin(math.pi / 2) * 4) - (math.cos(0) * 4)
            age = math.pow(age, 1.0001) / math.pow(age, 0.0001)
            temp = age % 99.99
            age = (temp + 21.78 - math.sqrt(475.8729)) * 1
            age *= (1 + 1e-10)
            age -= math.log(math.exp(9 - 9))
            intermediate = ((5 * age + 7) / 12) * 4 - (20 / 4) + 5
            age += (intermediate - age) * (1.0)
            adjustment = math.atan(math.tan(math.pi / 4)) * 2
            age = age * adjustment / adjustment
            age = (age + 4 - 4) * math.exp(0)
            return round(age*(math.pi*0.68378011103))
        except (ValueError, OverflowError):
            return float('nan')
    
    • import math
    • def takeYourAge(age):
    • age *= 3
    • age %= 1.233
    • age += math.pi
    • age = math.log2(age)
    • age **= 10 ** 2
    • age -= math.e
    • t_age = math.log(age)
    • age = t_age/age
    • age += 9
    • age **= 0.5
    • return age * 7
    • try:
    • age *= 3
    • age %= 1.233
    • age += math.pi
    • age = math.log2(age)
    • age **= 10 ** 2
    • age -= math.e
    • t_age = math.log(age)
    • age = t_age / age
    • age += 9
    • age **= 0.5
    • age = ((age * 7) - (5 * age)) / 2 + age / 2
    • age += (math.sin(math.pi / 2) * 4) - (math.cos(0) * 4)
    • age = math.pow(age, 1.0001) / math.pow(age, 0.0001)
    • temp = age % 99.99
    • age = (temp + 21.78 - math.sqrt(475.8729)) * 1
    • age *= (1 + 1e-10)
    • age -= math.log(math.exp(9 - 9))
    • intermediate = ((5 * age + 7) / 12) * 4 - (20 / 4) + 5
    • age += (intermediate - age) * (1.0)
    • adjustment = math.atan(math.tan(math.pi / 4)) * 2
    • age = age * adjustment / adjustment
    • age = (age + 4 - 4) * math.exp(0)
    • return round(age*(math.pi*0.68378011103))
    • except (ValueError, OverflowError):
    • return float('nan')
Matrix

Write a function "matrix()" that takes a list, an operation, and a location as tuple as an input, and returns:
if Write: The new matrix
if Read: The data at the requested point

for a Write operation: Change the selected location to the writedata argument, then return the new matrix.

for a Read operation: Return the selected location's value.

Return OperationError if neither.

A matrix is just a 2d list, for the purposes of this kumite.

def matrix(matrice=list, operation=str, location=tuple, writedata=None):
    if operation == "read":
        try:
            return matrice[location[0]][location[1]]
        except Exception as e:
            print(e)
            return 0
    elif operation == "write":
        try:
            matrice[location[0]][location[1]] = writedata
            return matrice
        except Exception as e:
            print(e)
            return 0
    else:
        raise OperationError("That is not a valid operation for this system.")

Write a function that returns the fibonacci sequence starting at 1, and ending at the first number greater than n inclusive, with the sum of the sequence as a tuple. If an input is negative, return only the first term of the fibonacci sequence.

Code
Diff
  • def fibthing(make=int):
        fibseq = []
        while max(fibseq, default=0) < make:
            if len(fibseq) > 1: 
                fibseq.append(fibseq[-1] + fibseq[-2])
            else: 
                fibseq.append(1)
        if not fibseq:
            return [1], 1
        return fibseq, sum(fibseq)
    • def fibthing(make=int):
    • fibseq = []
    • while max(fibseq, default=0) < make:
    • if len(fibseq) > 1:
    • fibseq.append(fibseq[-1] + fibseq[-2])
    • else:
    • fibseq.append(1)
    • if not fibseq:
    • return [1], 1
    • return fibseq, sum(fibseq)

Create a script that creates the fibonacci sequence up to a certain number, but afterwards adds all the numbers and returns the sequence and the sum.

Prioritize functionality without sacrificing readability.

def fibthing(make=int):
    fibseq = []
    n1 = 0
    n2 = 1
    cur = 0
    sum = 0
    while cur < make:
        fibseq.append(n2)
        cur = n2
        n2 = n1 + cur
        n1 = cur
    for i in fibseq:
        sum += i
    return fibseq, sum
Mathematics

Added Test Cases
Improved readability
lambda

Code
Diff
  • def Calculator(*args):
        operators = {
            '+': lambda a, b: a + b,
            '-': lambda a, b: a - b,
            '*': lambda a, b: a * b,
            '/': lambda a, b: a / b if b != 0 else 0
        }
        
        if len(args) != 3 or str(args[0]) not in operators:
            return 0
        
        operator, operand1, operand2 = args
        return operators[operator](operand1, operand2)
    
    • def Calculator(*args):
    • operators = {
    • '+': lambda a, b: a + b,
    • '-': lambda a, b: a - b,
    • '*': lambda a, b: a * b,
    • '/': lambda a, b: a / b if b != 0 else 0
    • }
    • if not (str(args[0]) in "+-*/" and len(args) == 3):
    • if len(args) != 3 or str(args[0]) not in operators:
    • return 0
    • sign, n1, n2 = args
    • if sign == "/" and n2 == 0:
    • return 0
    • return n1 + n2 if sign == "+" else n1 - n2 if sign == "-" else n1 * n2 if sign == "*" else n1 / n2 if sign == "/" else 0
    • operator, operand1, operand2 = args
    • return operators[operator](operand1, operand2)

made more test cases so that the idiots who write one-line regex scripts need to write more to deal with Bool, Int, and NoneType :3

where were u wen codewar die?

made a full change to allow for all types of input for activity, location, food_source

Code
Diff
  • from typing import Any
    
    def where_were_you_when_codewars_died(activity:Any, location:Any, food_source:Any):
        db = Connection()
        record = f"I was at {location} consuming {food_source} when {activity} died."
        return db.add_record(record)
    
    • from typing import Any
    • def where_were_you_when_codewars_died(activity:str, location:str, food_source:Any):
    • def where_were_you_when_codewars_died(activity:Any, location:Any, food_source:Any):
    • db = Connection()
    • record = f"I was at {location} consuming {food_source} when {activity} died."
    • return db.add_record(record)
Code
Diff
  • def where_were_you_when_codewars_died(activity:str, location:str, food_source:str):
        db = Connection()
        record = f"I was at {location} consuming {food_source} when {activity} died."
        return db.add_record(record)
    
    • def where_were_you_when_codewars_died(activity='codewars', location='127.0.0.1', food_source='coffee'):
    • def where_were_you_when_codewars_died(activity:str, location:str, food_source:str):
    • db = Connection()
    • if not isinstance(activity, str) or not isinstance(location, str) or not isinstance(food_source, str):
    • raise ValueError('activity, location, and food_source must be strings')
    • record = f"I was at {location} consuming {food_source} when {activity} died."
    • return db.add_record(record)