Python error handling

# ERROR HANDLING WITH TRY-EXCEPT

def echo(word, e=1):
     """Concatenate echo copies of a word"""
    word = '""

    try:
        echo_word = word1 * e

    except:
        print("word1 must be a string and echo must be an integer.")

    return echo

# Call the function
echo("hello", echo=5)


# ERROR HANDLING WITH RAISE

# Define shout_echo
def echo(word, e=1):
     """Concatenate echo copies of a word"""
    word = '""

    # Raise an error with raise
    if e < 0:
        raise ValueError('e must be greater than 0')

    echo = word1 * e

    # Return shout_word
    return echo

# Call the function
echo("hello", echo=5)


No comments:

Post a Comment