#Write a function called get_integer that takes as input one #variable, my_var. If my_var can be converted to an integer, #do so and return that integer. If my_var cannot be converted #to an integer, return a message that says, "Cannot convert!" # #For example, for "5" as the value of my_var, get_integer would #return the integer 5. If the value of my_var is the string #"Boggle.", then get_integer would return a string with the #value "Cannot convert!" # #Do not use any conditionals or the type() function.

Respuesta :

Answer:

#here is function in python

#function that return integer if input can be converted to int

#if not it will return a string "Cannot converted!!"

def get_integer(inp):

   try:

       return int(inp)

   except:

       return "Cannot convert!!"

print()

#call the function with different inputs

print(get_integer("5"))

print(get_integer("Boggle."))

print(get_integer(5.1))

print()

Explanation:

Define a function get_integer() with a parameter.In this function there is try  and except.First try will execute and if input can be converted to integer then  it will convert it into integer and return it.If it will not able to convert  the input into integer then except will return a string "Cannot convert!!".In the function get_integer(), there is no use of any conditionals or type function.

Output:

5

Cannot convert!!

5