Re: [問卦] 用python 要計算輸入任意數的平方根已回收
※ 引述《yoyodiy (廢文心得文大師)》之銘言:
: python 自學怎麼這麼難
: 有看沒有懂 難度比寫出一個99乘法表還難萬倍
: 如果不借助網路 怎樣自學最快?
: 如果鍵盤輸入任一數 求平方根
: 要寫出這樣的程式大概要學幾天?
: 有八卦嗎?
教你一個2000年前就有的方法
巴比倫法(Babylonian method)
1.給個數字A
2.猜他的平方根b
3.把猜的數字平方後,與A相減 就是| A-b^2 |
4.假如減後絕對值<可容許誤差範圍 本片結束
5.不然就計算新的猜測平方根=[b+(A/b)]/2
6.回步驟3
巴比倫人能計算方根2到 1.414212962962....,誤差少於百萬份之一
https://imgur.com/SiciocH
![](https://i.imgur.com/SiciocH.jpg)
挖出來的證據
user_response=input("Enter a number:")
number=float(user_response)
guess=number/2
accuracy=0.01
iteration=0
while abs(number-(guess**2))>accuracy:
print("Iteration",interation,"Guessed square is:",guess)
guess=(guess+(number/guess))/2
iteration=iteration+1
print("Original number is:",number)
print("Square root of the number is:",guess)
--
常函數和指數函數e^x走在街上,遠遠看到微分算子,常函數嚇得慌忙躲藏,說︰“被它
微分一下,我就什麼都沒有啦﹗”
指數函數不慌不忙道︰“它可不能把我怎么樣,我是e^x﹗”
指數函數與微分算子相遇。指數函數自我介紹道︰“你好,我是e^x。”
微分算子道︰“你好,我是d/dy﹗”
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.73.150
※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1521701250.A.550.html
推
03/22 14:50,
6年前
, 1F
03/22 14:50, 1F
→
03/22 14:50,
6年前
, 2F
03/22 14:50, 2F
推
03/22 15:14,
6年前
, 3F
03/22 15:14, 3F
推
03/22 15:41,
6年前
, 4F
03/22 15:41, 4F
→
03/22 15:42,
6年前
, 5F
03/22 15:42, 5F
推
03/22 15:46,
6年前
, 6F
03/22 15:46, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 5 篇):