# Python TQC考題108座標距離計算
x1=eval(input()) #2
y1=eval(input()) #1
x2=eval(input()) #5.5
y2=eval(input()) #8
dist=((x1-x2)**2+(y1-y2)**2)**0.5
import math #第二種作法
dist1=math.sqrt((x1-x2)**2+(y1-y2)**2)
# math.pow()可以做2次方,但**比較簡短
print(“( {:} , {:} )”.format(x1,y1))
print(“( {:} , {:} )”.format(x2,y2))
print(“Distance = {:.4f}”.format(dist))
print(dist1)
#第二種作法,只確認答案一樣,格式要再設定好


#tuple確實跟題目要的座標樣式很像
#可惜x1, x2的前後少了空白

#這一題基本上沒有難度
#就是考空白的位置是否正確








![Python: 如何判斷字符串內容是否為數字(整數或浮點數)? isinstance( eval( entry.get() ), (float, int) ) ; str.isdigit() #不包括小數點和負號 ; try~ except ValueError~ ; 正則表示法 regular expression ; pattern = ‘^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$’ Python: 如何判斷字符串內容是否為數字(整數或浮點數)? isinstance( eval( entry.get() ), (float, int) ) ; str.isdigit() #不包括小數點和負號 ; try~ except ValueError~ ; 正則表示法 regular expression ; pattern = ‘^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$’](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2023/05/20230512152430_3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言