_=([]!=["[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]"]) f=lambda:[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]
function returnhundred() {return 10 ** 2;}- _=([]!=["[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]"])
- f=lambda:[((_*(_+_)**(_*(_+_))**((_+_)*_))*((_+_)*(_+_))+(_*(_+_)**(_*(_+_))**((_+_)*_))*(_+_))+((_+_)*((_+_)*_))][(_+_)&(_*_)]
test.assert_equals(f(),100)
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.Test.assertEquals(returnhundred(),100)- test.assert_equals(f(),100)
f=lambda _:"EOvdedn"[_&1::2]
def even_or_odd(n):return "Even" if n% 2 == 0 else "Odd"- f=lambda _:"EOvdedn"[_&1::2]
import codewars_test as test from solution import f @test.describe("Basic tests") def test_group(): @test.it("test cases") def test_case(): test.assert_equals(f(0), "Even", "0 is even") test.assert_equals(f(2), "Even", "2 is even") test.assert_equals(f(3), "Odd", "3 is odd") test.assert_equals(f(24), "Even", "24 is even") test.assert_equals(f(25), "Odd", "25 is odd") test.assert_equals(f(115), "Odd", "115 is odd") test.assert_equals(f(98), "Even", "98 is even")
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import f
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")- @test.describe("Basic tests")
- def test_group():
@test.it("test case")- @test.it("test cases")
- def test_case():
test.assert_equals(even_or_odd(0), "Even", "0 is even")test.assert_equals(even_or_odd(2), "Even", "2 is even")test.assert_equals(even_or_odd(3), "Odd", "3 is odd")test.assert_equals(even_or_odd(24), "Even", "24 is even")test.assert_equals(even_or_odd(25), "Odd", "25 is odd")test.assert_equals(even_or_odd(115), "Odd", "115 is odd")test.assert_equals(even_or_odd(98), "Even", "98 is even")- test.assert_equals(f(0), "Even", "0 is even")
- test.assert_equals(f(2), "Even", "2 is even")
- test.assert_equals(f(3), "Odd", "3 is odd")
- test.assert_equals(f(24), "Even", "24 is even")
- test.assert_equals(f(25), "Odd", "25 is odd")
- test.assert_equals(f(115), "Odd", "115 is odd")
- test.assert_equals(f(98), "Even", "98 is even")
f=lambda _:'EOvdedn'[_&1::2]
def even_or_odd(n):return 'EOvdedn'[n & 1:: 2]- f=lambda _:'EOvdedn'[_&1::2]
import codewars_test as test from solution import f @test.describe("Basic tests") def test_group(): @test.it("test cases") def test_case(): test.assert_equals(f(0), "Even", "0 is even") test.assert_equals(f(2), "Even", "2 is even") test.assert_equals(f(3), "Odd", "3 is odd") test.assert_equals(f(24), "Even", "24 is even") test.assert_equals(f(25), "Odd", "25 is odd") test.assert_equals(f(115), "Odd", "115 is odd") test.assert_equals(f(98), "Even", "98 is even")
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import f
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")- @test.describe("Basic tests")
- def test_group():
@test.it("test case")- @test.it("test cases")
- def test_case():
test.assert_equals(even_or_odd(0), "Even", "0 is even")test.assert_equals(even_or_odd(2), "Even", "2 is even")test.assert_equals(even_or_odd(3), "Odd", "3 is odd")test.assert_equals(even_or_odd(24), "Even", "24 is even")test.assert_equals(even_or_odd(25), "Odd", "25 is odd")test.assert_equals(even_or_odd(115), "Odd", "115 is odd")test.assert_equals(even_or_odd(98), "Even", "98 is even")- test.assert_equals(f(0), "Even", "0 is even")
- test.assert_equals(f(2), "Even", "2 is even")
- test.assert_equals(f(3), "Odd", "3 is odd")
- test.assert_equals(f(24), "Even", "24 is even")
- test.assert_equals(f(25), "Odd", "25 is odd")
- test.assert_equals(f(115), "Odd", "115 is odd")
- test.assert_equals(f(98), "Even", "98 is even")
Exam results:
90% = 9
80% = 8
70% = 7
Anything else is a "fail".
def result(p):return "fail" if p<70 else p//10
def result(perc):if perc >= 90:return 9elif perc >= 80:return 8elif perc >= 70:return 7else:return "fail"- def result(p):return "fail" if p<70 else p//10
import codewars_test as test from solution import result @test.it("test case") def test_case(): test.assert_equals(result(75), 7) test.assert_equals(result(90), 9) test.assert_equals(result(56), "fail") test.assert_equals(result(89), 8) test.assert_equals(result(-10), "fail") test.assert_equals(result(0), "fail")
- import codewars_test as test
# TODO Write tests- from solution import result
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(result(75), 7)test.assert_equals(result(90), 9)test.assert_equals(result(56), "fail")test.assert_equals(result(89), 8)test.assert_equals(result(-10), "fail")test.assert_equals(result(200), 9)test.assert_equals(result(0), "fail")- @test.it("test case")
- def test_case():
- test.assert_equals(result(75), 7)
- test.assert_equals(result(90), 9)
- test.assert_equals(result(56), "fail")
- test.assert_equals(result(89), 8)
- test.assert_equals(result(-10), "fail")
- test.assert_equals(result(0), "fail")
even_or_odd = lambda n:'Even' if n%2==0 else 'Odd'
even_or_odd = lambda n:'Even' if n % 2 == 0 else 'Odd'- even_or_odd = lambda n:'Even' if n%2==0 else 'Odd'
import codewars_test as test from solution import even_or_odd @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(even_or_odd(0), "Even", "0 is even") test.assert_equals(even_or_odd(2), "Even", "2 is even") test.assert_equals(even_or_odd(3), "Odd", "3 is odd") test.assert_equals(even_or_odd(24), "Even", "24 is even") test.assert_equals(even_or_odd(25), "Odd", "25 is odd") test.assert_equals(even_or_odd(115), "Odd", "115 is odd") test.assert_equals(even_or_odd(98), "Even", "98 is even")
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- from solution import even_or_odd
# test.assert_equals(actual, expected, [optional] message)- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(even_or_odd(0), "Even", "0 is even")
- test.assert_equals(even_or_odd(2), "Even", "2 is even")
- test.assert_equals(even_or_odd(3), "Odd", "3 is odd")
- test.assert_equals(even_or_odd(24), "Even", "24 is even")
- test.assert_equals(even_or_odd(25), "Odd", "25 is odd")
- test.assert_equals(even_or_odd(115), "Odd", "115 is odd")
- test.assert_equals(even_or_odd(98), "Even", "98 is even")
Your task
Write a programm that takes number as an input, and returns "Even" if number is even; "Odd" if number is odd and "Zero" if number is zero.
Note: numbers can be negative. You will need to treat negativer numbers like positive: -2 is even; -1 or -5 is odd
def even_or_odd(n): if n == 0: # If number is zero, return zero return "Zero" elif n % 2 == 0: # If remainder of division by 2 is 0, number is even return "Even" else: # Else the number is odd return "Odd"
- def even_or_odd(n):
return 'Even' if n % 2 == 0 else 'Odd'- if n == 0: # If number is zero, return zero
- return "Zero"
- elif n % 2 == 0: # If remainder of division by 2 is 0, number is even
- return "Even"
- else: # Else the number is odd
- return "Odd"
import codewars_test as test # test.assert_equals(actual, expected, [optional] message) @test.describe("Basic tests") def test_group(): @test.it("Should work for positive numbers") def test_case(): test.assert_equals(even_or_odd(1), "Odd", 'If input is 1, should return "Odd"') test.assert_equals(even_or_odd(2), "Even", 'If input is 2, should return "Even"') test.assert_equals(even_or_odd(10), "Even", 'If input is 10, should return "Even"') test.assert_equals(even_or_odd(13), "Odd", 'If input is 13, should return "Odd"') test.assert_equals(even_or_odd(12385), "Odd", 'If input is 12385, should return "Odd"') @test.it("Should work for negative numbers") def test_case(): test.assert_equals(even_or_odd(-2), "Even", 'If input is -2, should return "Even"') test.assert_equals(even_or_odd(-5), "Odd", 'If input is -5, should return "Odd"') test.assert_equals(even_or_odd(-16), "Even", 'If input is -16, should return "Even"') test.assert_equals(even_or_odd(-10), "Even", 'If input is -10, should return "Even"') test.assert_equals(even_or_odd(-16354), "Even", 'If input is -16354, should return "Even"') @test.it("Should work for zero") def test_case(): test.assert_equals(even_or_odd(0), "Zero", 'If input is 0, should return "Zero"')
- import codewars_test as test
# TODO Write testsimport solution # or from solution import example- # test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")- @test.describe("Basic tests")
- def test_group():
@test.it("test case")- @test.it("Should work for positive numbers")
- def test_case():
test.assert_equals(even_or_odd(0), "Even", "0 is even")test.assert_equals(even_or_odd(2), "Even", "2 is even")test.assert_equals(even_or_odd(3), "Odd", "3 is odd")test.assert_equals(even_or_odd(24), "Even", "24 is even")test.assert_equals(even_or_odd(25), "Odd", "25 is odd")test.assert_equals(even_or_odd(115), "Odd", "115 is odd")test.assert_equals(even_or_odd(98), "Even", "98 is even")- test.assert_equals(even_or_odd(1), "Odd", 'If input is 1, should return "Odd"')
- test.assert_equals(even_or_odd(2), "Even", 'If input is 2, should return "Even"')
- test.assert_equals(even_or_odd(10), "Even", 'If input is 10, should return "Even"')
- test.assert_equals(even_or_odd(13), "Odd", 'If input is 13, should return "Odd"')
- test.assert_equals(even_or_odd(12385), "Odd", 'If input is 12385, should return "Odd"')
- @test.it("Should work for negative numbers")
- def test_case():
- test.assert_equals(even_or_odd(-2), "Even", 'If input is -2, should return "Even"')
- test.assert_equals(even_or_odd(-5), "Odd", 'If input is -5, should return "Odd"')
- test.assert_equals(even_or_odd(-16), "Even", 'If input is -16, should return "Even"')
- test.assert_equals(even_or_odd(-10), "Even", 'If input is -10, should return "Even"')
- test.assert_equals(even_or_odd(-16354), "Even", 'If input is -16354, should return "Even"')
- @test.it("Should work for zero")
- def test_case():
- test.assert_equals(even_or_odd(0), "Zero", 'If input is 0, should return "Zero"')