IndentationError: expected an output
IndentationError: expected an output
这里我在 python 中编码以获得任何字符串长度的输出。如果用户输入一个整数值然后打印 "Integer doesn't have length" 否则打印字符串的长度。
这是我的代码
def string_length(word):
if type(word) == int:
print("Integer doesn't have length")
else:
print("Length:", len(word))
word = input("Enter Word: ")
string_length(word)
print("End of Program!")
这是我的输出结果
Enter Word: 65
Length: 2
End of Program!
提前致谢!
因为python中的input
默认是字符串。您可以执行此操作的方法之一是检查字符串是否为数字。
if word.isnumeric():
print("Integer doesn't have a length")
这里我在 python 中编码以获得任何字符串长度的输出。如果用户输入一个整数值然后打印 "Integer doesn't have length" 否则打印字符串的长度。
这是我的代码
def string_length(word):
if type(word) == int:
print("Integer doesn't have length")
else:
print("Length:", len(word))
word = input("Enter Word: ")
string_length(word)
print("End of Program!")
这是我的输出结果
Enter Word: 65
Length: 2
End of Program!
提前致谢!
因为python中的input
默认是字符串。您可以执行此操作的方法之一是检查字符串是否为数字。
if word.isnumeric():
print("Integer doesn't have a length")