所以我有以下代码:
user_input = raw_input("Enter an integer, string or float:")
input_type = type(user_input)
if input_type == "str":
print "Your string was %s." % user_input
elif input_type == "int":
input_type = int(input_type)
print "Your integer was %d." % user_input
elif input_type == "float":
input_type = int(input_value)
print "Your float was %d." % user_input
else:
print "You did not enter an acceptable input."
Run Code Online (Sandbox Code Playgroud)
这不起作用 - 我相信因为if- 所以我把它改为:
if "str" in input_type
Run Code Online (Sandbox Code Playgroud)
并"int"为浮点数和整数,但得到一个错误:
Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud)