Best Python code snippet using refurb_python
is_even.py
Source:is_even.py
1# ===========================================================2# my solution3# ===========================================================4def is_even(x: int) -> bool:5 if x % 2 == 0:6 return True7 else:8 return False9print("Example:")10print(is_even(2))11assert is_even(2) == True12assert is_even(5) == False13assert is_even(0) == True14print("The mission is done! Click 'Check Solution' to earn rewards!")15# ===========================================================16# Best "Clear" Solution17# ===========================================================18def is_even(num: int) -> bool:19 return num & 1 == 020if __name__ == '__main__':21 print("Example:")22 print(is_even(2))23 # These "asserts" are used for self-checking and not for an auto-testing24 assert is_even(2) == True25 assert is_even(5) == False26 assert is_even(0) == True27 print("Coding complete? Click 'Check' to earn cool rewards!")28# ===========================================================29# Best "Creative" Solution30# ===========================================================31def is_even(num: int) -> bool:32 return bin(num)[-1]=='0'33if __name__ == '__main__':34 print("Example:")35 print(is_even(2))36 # These "asserts" are used for self-checking and not for an auto-testing37 assert is_even(2) == True38 assert is_even(5) == False39 assert is_even(0) == True40 print("Coding complete? Click 'Check' to earn cool rewards!")41 42 43 44 45# ===========================================================46# Best "Speedy" Solution47# ===========================================================48def is_even(num: int) -> bool:49 # your code here50 return not(num & 1)51 # think it faster than num %2 52if __name__ == '__main__':53 print("Example:")54 print(is_even(2))55 # These "asserts" are used for self-checking and not for an auto-testing56 assert is_even(2) == True57 assert is_even(5) == False58 assert is_even(0) == True59 print("Coding complete? Click 'Check' to earn cool rewards!")...
test_fce.py
Source:test_fce.py
1from fce import is_even234def test_fce_odd():5 assert is_even(374935) is False6 assert is_even('374935') is False7 assert is_even('three hundred seventy-four thousand nine hundred thirty-five') is False8 assert is_even('Three Hundred Seventy-Four Thousand Nine Hundred Thirty-Five') is False9 assert is_even('THREE HUNDRED SEVENTY-FOUR THOUSAND NINE HUNDRED THIRTY-FIVE') is False101112def test_fce_even():13 assert is_even(12) is True14 assert is_even(90) is True15 assert is_even('ninety') is True16 assert is_even('12') is True17 assert is_even('twelve') is True18 assert is_even('Twelve') is True19 assert is_even('TWELVE') is True20 assert is_even('EvEn') is True21 assert is_even('THREE HUNDRED SEVENTY-FOUR THOUSAND NINE HUNDRED THIRTY-Two') is True222324def test_fce_nonsense():25 assert is_even('Ahoj') is None26 assert is_even('Even6') is None27 assert is_even('Even-6') is None
...
test_is_even.py
Source:test_is_even.py
1#!/usr/bin/env python32# unit test for a given daily is_even()3from day005.is_even import is_even4def test():5 result = False6 try:7 assert( is_even( -2 ) == True )8 assert( is_even( -1 ) == False )9 assert( is_even( 0 ) == True )10 assert( is_even( 1 ) == False )11 assert( is_even( 2 ) == True )12 assert( is_even( 0x1000 ) == True )13 assert( is_even( 0x1001 ) == False )14 assert( is_even( 0x0FFFFFFF ) == False )15 assert( is_even( 0x10000000 ) == True )16 assert( is_even( 0x10000001 ) == False )17 result = True18 except AssertionError: print ("Assertion error.")19 except Exception as e: print ("Unexpected error: \"" + str(e) + "\"")20 return result...
minimal-i--if-boolean-then-boolean.py
Source:minimal-i--if-boolean-then-boolean.py
1def is_even(n):2 return n % 2 == 03is_even(2) # True4is_even(3) # False5is_even(10) # True6is_even(31) # False7is_even(666) # True8is_even(777) # False9is_even(3482034) # True...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!