Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何正确地将弧度转换为度_Python 3.x - Fatal编程技术网

Python 3.x 如何正确地将弧度转换为度

Python 3.x 如何正确地将弧度转换为度,python-3.x,Python 3.x,在45-45-90角度上,adj应该是5,我已经检查了我的数学,得到了正确的数学,但我不知道为什么它打印出6.8而不是5。您可以使用以下代码: angle1 = input("Enter the angle: ") angle1 = float(angle1) opp = input("Enter the opp side: ") opp = float(opp) answer = math.tan(math.degrees(angle1)) answe

在45-45-90角度上,adj应该是5,我已经检查了我的数学,得到了正确的数学,但我不知道为什么它打印出6.8而不是5。您可以使用以下代码:


angle1 = input("Enter the angle: ")
angle1 = float(angle1)
opp = input("Enter the opp side: ")
opp = float(opp)
answer = math.tan(math.degrees(angle1))
answer = float(answer)
adj = answer * opp
print(adj)

Enter the angle: 45
Enter the opp side: 5
-6.810224381304188

导入数学;math.degrees(math.pi/4)
返回
45
math.degrees()
将弧度转换为度,而不是相反。@PranavHosangadi是的,对于OP的意思,计算切线,他需要将
math.radians
应用于以度为单位的输入值。谢谢@Salio,这帮了大忙
import math
angle1 = input("Enter the angle: ")
angle1 = float(angle1)
opp = input("Enter the opp side: ")
opp = float(opp)
# answer = math.tan((angle1*math.pi)/180)

answer = math.tan(math.radians(angle1))
answer = float(answer)
adj = answer * opp
# print(math.ceil(adj))
print(round(adj))