尝试编写一个接收数字参数的函数,并检查并打印数字是正数、负数还是零 (Python 3)
Trying to write a function that receives a number argument and check and print if the number is positive, negative, or zero (Python 3)
这是我用来检查数字是正数、负数还是零的代码。
x = input("Enter a number to check if it is positive, negative or zero.")
def function():
if x == 0:
print("The number is zero.")
elif x > 0:
print("The number is positive.")
elif x < 0:
print("The number is negative.")
这是我得到的错误
File "<string>", line 4
print("The number is zero.")
^
IndentationError: expected an indented block
>
缩进在Python中非常重要:
if x == 0:
print("The number is zero.")
这是我用来检查数字是正数、负数还是零的代码。
x = input("Enter a number to check if it is positive, negative or zero.")
def function():
if x == 0:
print("The number is zero.")
elif x > 0:
print("The number is positive.")
elif x < 0:
print("The number is negative.")
这是我得到的错误
File "<string>", line 4
print("The number is zero.")
^
IndentationError: expected an indented block
>
缩进在Python中非常重要:
if x == 0:
print("The number is zero.")