首页 > 解决方案 > 我的文件中有错误,但在控制台中它可以工作

问题描述

当我在 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

标签: python

解决方案


缩进无效,替换这个:

    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")

推荐阅读