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
解决方案
缩进无效,替换这个:
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")
推荐阅读
- dynamics-crm - 如何将两个选项集关联到 Dynamics CRM 365 中的一个字段?
- openedge - 如何使用进度编辑器 11.6 将 .cls 编译为 .r
- swift - 如何将 UILabel 的文本保留在 safeArea 内?
- node.js - 基于 AWS 的可扩展 cron 架构
- django - 在 django wagtail 后端显示实时字数
- java - 从多个源 DTO 映射到一个目标
- node.js - 带有 Node API 的 Vue 应用程序:项目结构
- java - AVD android 设备无法连接到 localhost:3000
- java - 有没有办法压缩base64字符串?
- javascript - 使用 AJAX 处理从 CSV 文件中解析的变量