在我的文件中出错,但在控制台它工作

2024-09-25 02:33:11 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在run.py中编写它时,它会有意外的缩进,但当我在python控制台中编写它时,它会正常工作

from pip._vendor.distlib.compat import raw_input


def hello(a, b):
    if b != 0:
        wynik = a/b
        return wynik
    else:
        wynik = "No result"
        return wynik



a = raw_input('Number A:')
b = raw_input("Number B:")

    if not a is None and not b is None:
    print(hello(float(a),float(b)))
    else:
    print("A or B must be filled")

raw_input()

这是日志:

C:\Users\Student\PycharmProjects\untitled>run.py
  File "C:\Users\Student\PycharmProjects\untitled\run.py", line 17
    if not a is None and not b is None:
    ^
IndentationError: unexpected indent

Tags: andrunpynonenumberhelloinputraw
2条回答

无效缩进,替换为:

    if not a is None and not b is None:
    print(hello(float(a),float(b)))
    else:
    print("A or B must be filled")

有了这个:

if not a is None and not b is None:
    print(hello(float(a),float(b)))
else:
    print("A or B must be filled")

这样试试

rom pip._vendor.distlib.compat import raw_input


def hello(a, b):
    if b != 0:
        wynik = a/b
        return wynik
    else:
        wynik = "No result"
        return wynik


a = raw_input('Number A:')
b = raw_input("Number B:")

if not a is None and not b is None:
    print(hello(float(a),float(b)))
else:
    print("A or B must be filled")

raw_input()

相关问题 更多 >