Discuss / Python / 为什么提示缩进有问题?

为什么提示缩进有问题?

Topic source

YY饺子

#1 Created at ... [Delete] [Delete and Lock User]

import math def quadratic(a, b, c): q=bb-4ac if q<0: return ('wujieguo') elif q==0: return ('hanshujiewei' ) else: x1=(-b+math.sqrt(q))/(2a) x2=(-b-math.sqrt(q))/(2*a) return (x1,x2) print(quadratic(2,3,1))

YY饺子

#2 Created at ... [Delete] [Delete and Lock User]

代码里是有乘号的,不知为啥贴上去就没有了

YY饺子

#3 Created at ... [Delete] [Delete and Lock User]

又贴了一遍

import math
def quadratic(a,b,c):
    f=b**2-4*a*c
    if f<0:
      return ('方程无解')
    elif f==0:
      return (-b/(2*a))
    else:
      x1=(-b-math.sqrt(f))/(2*a)
      x2=(-b+math.sqrt(f))/(2*a)
      return (x1,x2)
print(quadratic(4,8,2))

ACrate

#4 Created at ... [Delete] [Delete and Lock User]

→_→统一四个空格

很有可能是你的空格和回车混用了,参考这个链接

https://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/

JOIEUH

#6 Created at ... [Delete] [Delete and Lock User]

你写的都错了,首先f=b2-4ac 有两个 第二,这个地方b不是乘2,而是乘b


  • 1

Reply