Return `5` without any numbers in Python

The challenge

Write a function that always returns 5

Sounds easy right? Just bear in mind that you can’t use any of the following characters: 0123456789*+-/

The solution in Python code

Option 1:

def unusual_five(): return len(['a','b','c','d','e'])
Code language: Python (python)

Option 2:

def unusual_five(): return len("five!")
Code language: Python (python)

Option 3:

def unusual_five(): return (int(True << True << True ^ True))
Code language: Python (python)

Option 4:

def unusual_five(): return "fiftyfive divided by eleven".count("e")
Code language: Python (python)

Test cases to validate our solution

import test from solution import unusual_five @test.describe("Fixed Tests") def fixed_tests(): @test.it('Should return 5') def basic_test_cases(): test.assert_equals(unusual_five(),5,"lol")
Code language: Python (python)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments