Return `5` without any numbers in Python

0 min read 86 words

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'])

Option 2:

def unusual_five():
    return len("five!")

Option 3:

def unusual_five():
    return (int(True << True << True ^ True))

Option 4:

def unusual_five():
    return "fiftyfive divided by eleven".count("e")

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")
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags