#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: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group() Python: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group()](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220901154435_19.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python: 如何對 pandas.DataFrame 兩欄位運算後,增加到最後一欄? df[‘sum_AB’] = df.apply(sum_ab, axis=1) ; lambda函式 Python: 如何對 pandas.DataFrame 兩欄位運算後,增加到最後一欄? df[‘sum_AB’] = df.apply(sum_ab, axis=1) ; lambda函式](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230314200417_4.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python四種型態增加元素 list.append(元素), tuple = tuple + (元素, ), set.add(元素), dict[key]=value Python四種型態增加元素 list.append(元素), tuple = tuple + (元素, ), set.add(元素), dict[key]=value](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/05/20220513083711_22.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言