Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
from random import randint
quotes= ["Captain Teemo on duty.","Yes, sir!", "Armed and ready.","Reporting in.","Hut, two, three, four.","I'll scout ahead!","Swiftly!","That's gotta sting.","Never underestimate the power of the Scout's code.","Size doesn't mean everything."]
def motivation():
return quotes[randint(0,len(quotes)-1)]
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
print(motivation())
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
Task
- Debug the
authenticated_request
function. There are several bugs in this code preventing it from executing correctly. If properly debugged, it will autheniticate the request to the given url, and return a200
HTTP response status code (which means there was a successfful response).
Rule
- Do not edit the
URL
constant in theCode
orPreloaded
tab. The purpose of this kumite is to debug the code within theauthenticated_request
method, and generated a200
response code to this given url.
Hint
Click to view
- You must look at the
URL
constant in thePreloaded
tab to successfully debug this. - There is an incorrect:
data structure
,method
, andparameter
.
import requests
def authenticated_request():
credentials = {'username': 'seraph', 'password': 'secret'}
try:
response = requests.post(url=URL, data=credentials)
except (ValueError, NameError, TypeError) as e:
return False
else:
return response.status_code == 200
import codewars_test as test
from solution import authenticated_request
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(authenticated_request(), True)
def get_of_my_lawn(on_my_lawn):
if on_my_lawn:
return "get of my lawn"
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(1 + 1, 2)
Background information
Time is measured differently on each planet. One Earth year is equivalent to the amount of
time it takes for Earth to orbit the sun. On other planets, this orbital time is shorter or longer.
Planet | Rotation period (hours) | Orbit period (days) |
---|---|---|
Mercury | 58.6 | 88.0 |
Venus | 243 | 224.7 |
Earth | .99 | 365.25 |
Mars | 1.03 | 687 |
Jupiter | .41 | 4331 |
Saturn | .45 | 10747 |
Uranus | .72 | 30589 |
Neptune | .67 | 59800 |
Pluto | 6.39 | 90560 |
- Source : nasa.org
Task
Create a function named planetary_age
that takes two parameters, planet
, and age
which are str
, and int
respectively. The function should calculate your age on other planets.
def planetary_age(planet, age):
hashmap = {
'mercury': {'rotation': 58.6, 'revolution': 88.0},
'venus': {'rotation': 243, 'revolution': 224.7},
'earth': {'rotation': .99, 'revolution': 365.25},
'mars': {'rotation': 1.03, 'revolution': 687},
'jupiter': {'rotation': .41, 'revolution': 4331},
'saturn': {'rotation': .45, 'revolution': 10747},
'uranus': {'rotation': .72, 'revolution': 30589},
'neptune': {'rotation': .67, 'revolution': 59800},
'pluto': {'rotation': 6.39, 'revolution': 90560}
}
earth_days = age * hashmap['earth']['revolution']
planet_age = earth_days / hashmap[planet]['revolution']
days = earth_days / hashmap[planet]['rotation']
return planet_age, days
import codewars_test as test
from solution import planetary_age
import random
@test.describe("Example")
def test_group():
@test.it("test case: testing ages (13, 20, 55, 76) against all 12 planets")
def test_case():
planets = ('mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune', 'pluto')
age = 13
s1 = ((53.95738636363637, 81.02815699658703),
(21.13150867823765, 19.540123456790123),
(13.0, 4796.212121212121),
(6.9115720524017465, 4609.9514563106795),
(1.0963403371045948, 11581.09756097561),
(0.44182097329487297, 10551.666666666666),
(0.1552273693157671, 6594.791666666667),
(0.07940217391304348, 7086.940298507462),
(0.052432089222614844, 743.075117370892),)
for planet, expected in zip(planets, s1):
test.assert_equals(planetary_age(planet, age), expected)
age = 20
s2 = ((83.01136363636364, 124.65870307167235),
(32.510013351134845, 30.061728395061728),
(20.0, 7378.787878787879),
(10.633187772925764, 7092.233009708738),
(1.6866774416993766, 17817.07317073171),
(0.6797245742998046, 16233.333333333332),
(0.23881133740887248, 10145.833333333334),
(0.12215719063545151, 10902.985074626866),
(0.08066475265017668, 1143.192488262911),)
for planet, expected in zip(planets, s2):
test.assert_equals(planetary_age(planet, age), expected)
age = 55
s3 = ((228.28125, 342.811433447099),
(89.40253671562083, 82.66975308641975),
(55.0, 20291.666666666668),
(29.24126637554585, 19503.640776699027),
(4.638362964673286, 48996.9512195122),
(1.8692425793244627, 44641.666666666664),
(0.6567311778743993, 27901.041666666668),
(0.3359322742474916, 29983.20895522388),
(0.22182806978798586, 3143.779342723005),)
for planet, expected in zip(planets, s3):
test.assert_equals(planetary_age(planet, age), expected)
age = 76
s4 = ((315.4431818181818, 473.70307167235495),
(123.53805073431242, 114.23456790123457),
(76.0, 28039.39393939394),
(40.4061135371179, 26950.485436893203),
(6.409374278457631, 67704.87804878049),
(2.5829533823392574, 61686.666666666664),
(0.9074830821537154, 38554.16666666667),
(0.46419732441471573, 41431.343283582086),
(0.3065260600706714, 4344.131455399061),)
for planet, expected in zip(planets, s4):
test.assert_equals(planetary_age(planet, age), expected)
def find_what(txt):
if txt.find('Python'):
return 'Found Python!'
else:
return 'Python not found!'
import codewars_test as test
from solution import find_what
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
samples = ('codewarz', 'kumite','shikataganai', '仕方がない')
for s in samples:
test.assert_equals(find_what(s), 'Found Python!')
def solution():
return 10
import codewars_test as test
# TODO Write tests
from solution import solution
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(solution(), 10)
return:
w - h - y
def why():
return 'w - h - y'
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(why(), 'w - h - y')
Find the largest number from the string and output in the number format
def my_first_kumite(s):
s = list(s)
for i in range(len(s)):
s[i] = int(s[i])
return max(s)
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(my_first_kumite("1234564569"), 9)
test.assert_equals(my_first_kumite("3756983475698"), 9)
test.assert_equals(my_first_kumite("847235463524632465"), 8)
test.assert_equals(my_first_kumite("456462534652347"), 7)
test.assert_equals(my_first_kumite("62314231434151"), 6)
test.assert_equals(my_first_kumite("54124231124"), 5)
test.assert_equals(my_first_kumite("423123213213"), 4)
test.assert_equals(my_first_kumite("21213121"), 3)
test.assert_equals(my_first_kumite("1211111121"), 2)
your task:
return a max lenght word in line, but return len word without another symbols
example:
- 'marry, ksnfgjji233jc, harry!@#':
ksnfgjji233jc, - len this word is 14, len word without another symbols = 10 (ksnfgjjijc)
should return: ksnfgjji233jc,
def lenght_line(line='marry, ksnfgjji233jc, harry!@#'):
return 'ksnfgjji233jc,'
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(lenght_line(), 'ksnfgjji233jc,')
You must return a string value from the list. Good luck!
def search_str(s):
for i in s:
if isinstance(i, str):
return i
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(search_str([1, 2, 3, "text", 4, 5]), "text")
test.assert_equals(search_str([1, 2, 3, "Egor 3.14 door", 4, 5]), "Egor 3.14 door")