Random Number Even/Odd Determiner

  • Share this:

Code introduction


This function generates a random number between 1 and 100 and determines if the number is even or odd. If the random number is even, it returns 'Even'. If it is odd, it returns 'Odd'.


Technology Stack : The code uses the nose library for random number generation and conditional logic.

Code Type : The type of code

Code Difficulty : Advanced


                
                    
import nose.tools as nt

def test_random_function():
    # Generate a random number between 1 and 100
    random_number = nt.random.randint(1, 100)
    
    # Check if the random number is even or odd
    if random_number % 2 == 0:
        result = "Even"
    else:
        result = "Odd"
    
    return result