Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

InputType.py Submit Run Grades Reset #Recall that input from a user is always in

ID: 3704041 • Letter: I

Question

InputType.py Submit Run Grades Reset #Recall that input from a user is always in the form of a string 2 #Ilrite a function called "input-type" that gets user input and 3 #dete ines what kind of string the user entered. The user input 4 #will be supplied as an argument to the function like normal 5# 6 # -Your function should return "integer" if the string only 7 # contains characters 0-9 8 # Your function should return "float" if the string only boolean boolean boolean boolean # contains the numbers 0-9 and at most one period 10 # -You should return "boolean" if the user enters "True" or 11# "False" 12 # -otherwise, you should return "string". 14 te your function here! 16 def input type(xxx): 17 18 19 try: if xxxTrue" or "False": if xxx.isdigit): if xxx-count("-")--1: return "string return "boolean" return "floot" except: 26 27 #Below are some lines of code that will test your function 28 #You can change the value of the variable(s) to test your 29 #function with different inputs 30# 31 #If your function works correctly, this will originally 32 #print: 33 #string 34 #boolean 35 #float 36 #integer 37 print (input type() 38 print (input type("False) 39 print (input_typ(7.432621)) 40 print (input_type( "2788")) 41

Explanation / Answer

def input_type(xxx): try: if xxx in ["True", "False"]: return "boolean" if xxx.isdigit(): return "integer" if xxx.count(".") == 1: ind = xxx.index(".") if xxx[0:ind].isdigit() and xxx[ind+1:].isdigit(): return "float" except: pass return "string" print(input_type("")) print(input_type("False")) print(input_type("7.432621")) print(input_type("2788"))