Re: [问卦] 用python 要计算输入任意数的平方根

楼主: Gold740716 (项为之强)   2018-03-22 15:50:58
如果简单用近似算法,
用 javascript 写:
<script>
function promptSquareRoot() {
const input = prompt('请输入要取平方根的数')
const square = Number(input)
let guess = Math.random() * square
const allowError = 0.1
let error
do {
guess = (square / guess + guess) / 2
error = Math.abs(guess * guess - square)
} while (error > allowError)
alert(`${square} 的平方根是 ${guess}`)
}
promptSquareRoot()
</script>
可以用 BBSJS 执行喔。
http://gholk.github.io/bbsjs.html
或是直接复制 <script> 内的程式,
在网页上按 F12 贴上执行。
※ 引述《oway15 (clinical lycanthropy)》之铭言:
: ※ 引述《yoyodiy (废文心得文大师)》之铭言:
: : python 自学怎么这么难
: : 有看没有懂 难度比写出一个99乘法表还难万倍
: : 如果不借助网络 怎样自学最快?
: : 如果键盘输入任一数 求平方根
: : 要写出这样的程式大概要学几天?
: : 有八卦吗?
: pw=input("输入一个数字:")
: gg=input("输入平方值:")
: res=int(pw)**int(gg)
: print("结果为%d" % (res))
: 大GUY这样
: 就四行吧
: 你那个九九乘法表大概巢状循环打打就出来了吧
: 难度都是看五分钟就会了ㄅ
: 最近要整理实验资料开始学这个
: python最后感觉都是在学套件语法
: 另外请问把资料撷取器丢给python处理
: 现在都是撷取器做成CSV再给python抓
: 有没有更简单的办法R?

Links booklink

Contact Us: admin [ a t ] ucptt.com