我正在 Exercism 網(wǎng)站上做一個(gè)練習(xí),我對如何開始這個(gè)練習(xí)有點(diǎn)困惑。我不想要任何詳細(xì)的答案;我只是在尋找如何開始的正確方向。當(dāng)給定一組 (x, y) 坐標(biāo)時(shí),我想知道是否有任何特定的 Python 模塊、函數(shù)等可以幫助我確定該點(diǎn)在網(wǎng)格上的位置,尤其是與圓相關(guān)的位置在以 (0, 0) 為中心的網(wǎng)格上。我希望這對我正在尋找的東西更具體一點(diǎn)!我在編寫程序時(shí)沒有任何特別的問題(還沒有!),但我什至不知道如何開始,因?yàn)槲也淮_定是否需要從頭開始編寫一個(gè)函數(shù)來解決上述所有問題,或者如果 Python 已經(jīng)有一些東西可以幫助完成這個(gè)特定的任務(wù)。謝謝!Write a function that returns the earned points in a single toss of a Darts game.Darts is a game where players throw darts to a target.In our particular instance of the game, the target rewards with 4 different amounts of points, depending on where the dart lands:If the dart lands outside the target, player earns no points (0 points).If the dart lands in the outer circle of the target, player earns 1 point.If the dart lands in the middle circle of the target, player earns 5 points.If the dart lands in the inner circle of the target, player earns 10 points.The outer circle has a radius of 10 units (This is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered to the same point (That is, the circles are concentric) defined by the coordinates (0, 0).Write a function that given a point in the target (defined by its real cartesian coordinates x and y), returns the correct amount earned by a dart landing in that point.
1 回答

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
解決這個(gè)問題的一種方法是使用勾股定理來計(jì)算飛鏢和中心之間的距離。
r = math.sqrt(x*x+y*y)
這將為您提供飛鏢和目標(biāo)中心之間的距離。
添加回答
舉報(bào)
0/150
提交
取消