我正在使用vim编辑器作为python IDE.下面是一个简单的python程序来计算数字的平方根:
import cmath
def sqrt():
try:
num = int(input("Enter the number : "))
if num >= 0:
main(num)
else:
complex(num)
except:
print("OOPS..!!Something went wrong, try again")
sqrt()
return
def main(num):
squareRoot = num**(1/2)
print("The square Root of ", num, " is ", squareRoot)
return
def complex(num):
ans = cmath.sqrt(num)
print("The Square root if ", num, " is ", ans)
return
sqrt()
Run Code Online (Sandbox Code Playgroud)
警告是:
1-square-root.py|2 col 1 C| E302 expected 2 blank lines, found 0 [pep8]
1-square-root.py|15 col 1 C| E302 expected 2 blank lines, found 1 [pep8]
1-square-root.py|21 col 1 C| E302 expected 2 blank lines, found 0 [pep8]
Run Code Online (Sandbox Code Playgroud)
你能告诉我这些警告为什么会来吗?
Leb*_*Leb 35
import cmath
def sqrt():
try:
num = int(input("Enter the number : "))
if num >= 0:
main(num)
else:
complex_num(num)
except:
print("OOPS..!!Something went wrong, try again")
sqrt()
return
def main(num):
square_root = num**(1/2)
print("The square Root of ", num, " is ", square_root)
return
def complex_num(num):
ans = cmath.sqrt(num)
print("The Square root if ", num, " is ", ans)
return
sqrt()
Run Code Online (Sandbox Code Playgroud)
之前的将解决您的PEP8问题.导入后,您需要在开始代码之前有2个新行.此外,每个之间def foo()你需要有2个.
在您的情况下,导入后您有0,并且每个函数之间有1个换行符.作为PEP8的一部分,您需要在代码结束后使用换行符.不幸的是,当我将代码粘贴到此处时,我不知道如何显示它.
注意命名,它也是PEP8的一部分.我改变complex,以complex_num防止与内置的混乱complex.
最后,他们只是警告,如果需要可以忽略它们.
| 归档时间: |
|
| 查看次数: |
51454 次 |
| 最近记录: |