本文介绍了我想在Python中找到cuberoot ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在phython我知道找到一个完美立方体的立方根,但我怎么能找到一个数字的立方根,如9,7,17​​ ...这不是一个完美的立方体我想要大致的回答如下:

例如:



输入:num = 9

输出:2.08



我尝试过:



in phython i know find a cube root of perfect cube but how i can find a cube root of number like 9,7,17...which are not a perfect cube i want approx answer like:
example:

input:num=9
output:2.08

What I have tried:

cube=int(input(' enter a vlue to find it cube root,(vlue must be >1):'))
epsilon=0.01
num_guess=0
low=0
high=cube
guess=(high+low)/2.0
while abs(guess**3-cube)>=epsilon:
	if guess**3<cube:
			low=guess
	else:	#guess**3>=guess
		high=guess
		guess=(high+low)/2.0
		num_guess+1

print('number of guess=',num_guess)
print(guess)

推荐答案


n=int(input('enter a value of which root you want to find(ex.for squreroot type 2,cuberoot type 3):'))
d=int(input('enter a no. to find  root of it:'))
x=1/n
print('your ans.=',d**x)

                                         #now its look like pythonikkkkk.....


这篇关于我想在Python中找到cuberoot ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:50