Creating a function

Report a typo

Now, it's time to create your own function in the shell. Take the function my_sqrt() from the theory part as an example and change it as follows:

  • The function should return the result of math.sqrt() when the input is an integer or a float.

  • The function should return the string "The string should be converted into a numeric data type" if the passed argument was a string.

  • The function should return None for other inputs.

You can test this function in the shell until it works fine, then copy it into the field below, and we'll see if it is correct.

Note: Your function need to return the correct values, you shouldn't print anything.

Write a program in Python 3
import math


# Modify this function in the shell and copy the new version here
def my_sqrt(value):
if type(value) is not int and type(value) is not float:
return None
else:
return(math.sqrt(value))
___

Create a free account to access the full topic