Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
def is_prime(num): if not num&1 and num != 2: return False for i in range(3, int(num ** 0.5) + 1, 2): if not num % i: return False return True def get_primes(max_num): return [i for i in range(2, max_num) if is_prime(i)]
import math- def is_prime(num):
if(not (num&1) and num != 2):- if not num&1 and num != 2:
- return False
for i in range(3, int(math.sqrt(num)) + 1, 2):if (num % i) == 0:- for i in range(3, int(num ** 0.5) + 1, 2):
- if not num % i:
- return False
- return True
- def get_primes(max_num):
- return [i for i in range(2, max_num) if is_prime(i)]
import random def rubegoldberg(): find = "codewars" total = 1 - len(find) for x, y in enumerate(find): if x % 2: total -= ord(y) - 97 else: total += ord(y) - 97 for n in random.sample([i for i in range(10)], 10): if n: a = 1 / n else: return total
import string- import random
- def rubegoldberg():
alpha = string.ascii_lowercasefind, total = "codewars", 1- find = "codewars"
- total = 1 - len(find)
- for x, y in enumerate(find):
if x % 2 == 0:total += alpha.index(y)- if x % 2:
- total -= ord(y) - 97
- else:
total -= alpha.index(y)total -= len(find)nums = []for i in range(0, 10):nums.append(i)random.shuffle(nums)try:for n in nums:- total += ord(y) - 97
- for n in random.sample([i for i in range(10)], 10):
- if n:
- a = 1 / n
except ZeroDivisionError:return total- else:
- return total
Fundamentals
Numbers
Data Types
Mathematics
Algorithms
Logic
def temperature_convert(temperature): value, a, b = temperature if a == b: return value converter = {'ck': value + 273.15, 'cr': (value * 1.8) + 491.67, 'cf': (value * 1.8) + 32, 'rc': (value - 491.67) * (5/9), 'rk': value * (5/9), 'rf': value - 459.67, 'kc': value - 273.15, 'kr': value * 1.8, 'kf': ((value - 273.15) * 1.8) + 32, 'fc': (value - 32) * (5/9), 'fk': ((value - 32) * (5/9)) + 273.15, 'fr': value + 459.67} return int(converter[str(a + b)])
- def temperature_convert(temperature):
- value, a, b = temperature
- if a == b:
- return value
if temperature[1] == temperature[2]:return temperature[0]- converter = {'ck': value + 273.15,
- 'cr': (value * 1.8) + 491.67,
- 'cf': (value * 1.8) + 32,
- 'rc': (value - 491.67) * (5/9),
- 'rk': value * (5/9),
- 'rf': value - 459.67,
- 'kc': value - 273.15,
- 'kr': value * 1.8,
- 'kf': ((value - 273.15) * 1.8) + 32,
- 'fc': (value - 32) * (5/9),
- 'fk': ((value - 32) * (5/9)) + 273.15,
- 'fr': value + 459.67}
converter = {'ck': '{} + 273.15','cr': '({} * 1.8) + 491.67','cf': '({} * 1.8) + 32','rc': '({} - 491.67) * (5/9)','rk': '{} * (5/9)','rf': '{} - 459.67','kc': '{} - 273.15','kr': '{} * 1.8','kf': '(({} - 273.15) * 1.8) + 32','fc': '({} - 32) * (5/9)','fk': '(({} - 32) * (5/9)) + 273.15','fr': '{} + 459.67'}value = temperature[0]formula = converter[str(temperature[1] + temperature[2])]return int(eval(formula.format(value)))- return int(converter[str(a + b)])
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
def is_prime(num): for i in range(2, num): if (num % i) == 0: return False return True def get_primes(max_num): return [i for i in range(2, max_num) if is_prime(i)]
- def is_prime(num):
for i in range(2,num):- for i in range(2, num):
- if (num % i) == 0:
- return False
- return True
- def get_primes(max_num):
list_primes = []for num1 in range(2,max_num):if is_prime(num1):list_primes.append(num1)return list_primes- return [i for i in range(2, max_num) if is_prime(i)]
pin_validator = lambda pin : len(str(pin)) == 5
def pin_validator(pin):return len(str(pin)) == 5 and str(pin).isdigit()- pin_validator = lambda pin : len(str(pin)) == 5
# TODO: Replace examples and use TDD by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) # You can use Test.describe and Test.it to write BDD style test groupings test.assert_equals(pin_validator(13453), True) test.assert_not_equals(pin_validator(3353), True)
# TODO: Replace examples and use TDD by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)# You can use Test.describe and Test.it to write BDD style test groupingstest.assert_equals(pin_validator(13453), True)- # TODO: Replace examples and use TDD by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
- # You can use Test.describe and Test.it to write BDD style test groupings
- test.assert_equals(pin_validator(13453), True)
- test.assert_not_equals(pin_validator(3353), True)