#Python TQC考題506 一元二次方程式
def compute(a,b,c):
cond=b**2-4*a*c
if cond >=0:
root1=(-b+cond**0.5)/(2*a)
root2=(-b-cond**0.5)/(2*a)
return root1,root2
else: return 0
a=eval(input())
b=eval(input())
c=eval(input())
if compute(a,b,c)==0:
print(“Your equation has no root.”)
else:
root1,root2=compute(a,b,c)
print(“{}, {}”.format(root1,root2))

# 第二次做
# 把print寫進去compute函數中
# return那裡改為print()
# 精簡了末段為print而做的if…else…
def compute(a,b,c):
cond=b**2-4*a*c
if cond >= 0:
root1=(-b+cond**0.5)/(2*a)
root2=(-b-cond**0.5)/(2*a)
print(root1,root2)
#其實少了題目要的逗點
else:print(“Your equation has no root.”)
a=eval(input())
b=eval(input())
c=eval(input())
compute(a,b,c)

#root1 , root2中間的逗點也是題目要的:

#題目沒說
#但是看輸出結果
#print()中要下格式 %.1f

![Python: matplotlib如何控制legend的位置? ax.legend(handles=[patch], loc=’upper left’, bbox_to_anchor=(6/10, 3/5) Python: matplotlib如何控制legend的位置? ax.legend(handles=[patch], loc=’upper left’, bbox_to_anchor=(6/10, 3/5)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/05/20230502163945_79.png?quality=90&zoom=2&ssl=1&resize=350%2C233)






![Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index) Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250420212553_0_6fb2c3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言