【发布时间】:2013-06-27 01:18:36
【问题描述】:
所以我有以下代码:
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
为什么会出现这个问题,我该如何解决?
【问题讨论】:
标签: python function if-statement python-2.7