課程
/后端開發
/Python
/初識Python
不知道是邏輯問題還是代碼哪里語法錯誤,看了好久,沒找出來原因
2017-03-11
源自:初識Python 7-4
正在回答
第十二行的2a改成2*a
Emmanuels 提問者
謝謝,有兩處沒有寫好,你發現了一處。很感謝
import math
def quadratic_equation(a, b, c):
? ? dit = b*b-4*a*c
? ? if dit > 0:
? ? ? ?d = math.sqrt(dit)
? ? ? ?x1 = (-b + d)/(2*a)
? ? ? ?x2 = (-b - d)/(2*a)
? ? ? ?return x1,x2
? ? elif dit == 0:
? ? ? ?x1 = -b/(2*a)
? ? ? ?return x1
? ? else:
? ? ? ?return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
mathfather
Emmanuels 提問者 回復 mathfather
舉報
學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-03-11
第十二行的2a改成2*a
2017-03-11
謝謝,有兩處沒有寫好,你發現了一處。很感謝
import math
def quadratic_equation(a, b, c):
? ? dit = b*b-4*a*c
? ? if dit > 0:
? ? ? ?d = math.sqrt(dit)
? ? ? ?x1 = (-b + d)/(2*a)
? ? ? ?x2 = (-b - d)/(2*a)
? ? ? ?return x1,x2
? ? elif dit == 0:
? ? ? ?x1 = -b/(2*a)
? ? ? ?return x1
? ? else:
? ? ? ?return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)