Sunday, October 1, 2023
HomeSoftware EngineeringReturn `5` with none numbers in Python

Return `5` with none numbers in Python


The problem

Write a operate that at all times returns 5

Sounds simple proper? Simply keep in mind which you can’t use any of the next characters: 0123456789*+-/

The answer in Python code

Choice 1:

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

Choice 2:

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

Choice 3:

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

Choice 4:

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

Take a look at instances to validate our resolution

import take a look at
from resolution import unusual_five

@take a look at.describe("Fastened Checks")
def fixed_tests():
    @take a look at.it('Ought to return 5')
    def basic_test_cases():
        take a look at.assert_equals(unusual_five(),5,"lol")
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments