Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to write a function that receives a number argument and check and print if the number is positive, negative, or zero (Python 3)

Here is my code to check is the number is positive, negative or 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.")

Here is the error I get

File "<string>", line 4
    print("The number is zero.")
    ^
IndentationError: expected an indented block
> 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Indentation is very important in Python:

if x == 0:
    print("The number is zero.")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading