简体   繁体   中英

python shell gives syntax error when running a print() ,however the same code executes in jupytr notebook

def test_number(x, y):
    if x == y or abs(x-y) == 5 or (x+y) == 5:
        return True
    else:
        return False

    print(test_number(7, 2))
    print(test_number(3, 2))
    print(test_number(2, 2))

When run in jupyter notebook, it executes with O/P:True when run in python shell cmd, it gives invalid syntax附上错误图片

Error is in the ident. Python is an ident base language. Correct example.

def test_number(x, y):
    return x == y or abs(x-y) == 5 or (x+y) == 5

print(test_number(7, 2))
print(test_number(3, 2))
print(test_number(2, 2))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM