所以我有以下代码:
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."
我认为这是行不通的if,因此我将其更改为:
if "str" in input_type
和"int"浮子和整数,但得到一个错误:
Traceback (most recent call last):
File "types.py", line 4, in <module>
if "str" in input_type:
TypeError: argument of type 'type' is not iterable
为什么会得到这个,我该如何解决?
湖上湖
呼唤远方
相关分类