新聞中心
上學(xué)的時候,數(shù)學(xué)是一批小伙伴們的噩夢,相比較語文的死記硬背方面,真的是讀題一分鐘,解題一小時。小編當(dāng)年也被數(shù)學(xué)困住了,當(dāng)然現(xiàn)在肯定是要改變這種情況。學(xué)習(xí)了python后,小編就找到了很多能夠解決數(shù)學(xué)方面的技巧。今天就分?jǐn)?shù)這個問題,小編把自己所學(xué)到的內(nèi)容分享給大家。

會寧網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)公司公司2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)公司。
嘗試編寫一段計算直線斜率的代碼,正在使用3.6。
y1 = float(input("First y point: "))
y2 = float(input("Second y point: "))
x1 = float(input("First X point: "))
x2 = float(input("Second X point: "))
slope = (y2 - y1)/(x2 - x1)
print("The slope is:",slope)
每當(dāng)輸入使答案不合理的數(shù)字時,答案就會變成十進(jìn)制。是否可以將其保留為零呢?
解決:
from fractions import Fraction
y1 = int(input("First y point: "))
y2 = int(input("Second y point: "))
x1 = int(input("First X point: "))
x2 = int(input("Second X point: "))
slope = Fraction(y2 - y1, x2 - x1)
print("The slope is:", slope, "=", float(slope))
輸入和輸出:
First y point: 5 Second y point: 7 First X point: 10 Second X point: 15 The slope is: 2/5 = 0.4
以上就是小編解決分?jǐn)?shù)問題的一個方法啦,相信有了今天的學(xué)習(xí),小伙伴們應(yīng)該不會對數(shù)學(xué)再感到害怕了。以后有很多的實(shí)用數(shù)學(xué)編程技巧,小編也會分享給大家的~
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:如何用python3輸出分?jǐn)?shù)?
當(dāng)前路徑:http://www.5511xx.com/article/dpsdhje.html


咨詢
建站咨詢
