Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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中将浮点值打印为度_Python 3.x_Geometry_Computational Geometry_Angle - Fatal编程技术网

Python 3.x 在python 3中将浮点值打印为度

Python 3.x 在python 3中将浮点值打印为度,python-3.x,geometry,computational-geometry,angle,Python 3.x,Geometry,Computational Geometry,Angle,给定90度角,以度为单位打印平分角。 import math #given angle abc = 90 #m is midpoint of ac, therefor abm = abc/2 mbc = abc - abm degrees = math.degrees(mbc) print(degrees) 但是当我打印出来的时候,我得到了2578.3100780887044 如果我不使用math.degrees(),那么我会得到: mbc = abc - abm #degrees =

给定90度角,以度为单位打印平分角。

import math 

#given angle
abc = 90

#m is midpoint of ac, therefor
abm = abc/2
mbc = abc - abm
degrees = math.degrees(mbc)
print(degrees)
但是当我打印出来的时候,我得到了2578.3100780887044

如果我不使用math.degrees(),那么我会得到:

mbc = abc - abm
#degrees = math.degrees(mbc)
print(mbc)
45.0

但我需要的是:45度


我找到了math.radians()和math.degrees(),但我觉得我缺少了一些东西。有什么帮助吗?

Python 3为每个整数或浮点除法返回一个浮点。如果您愿意,您可以将结果写下来:
abm=int(abc/2)
。这将给你一个整数mbc。
另一方面,
math.degrees()。如果你想确定转换的结果,你可以做
degrees=int(math.degrees(mbc))

好吧,我想重点是我想要45度这个数字。我不想把45弧度转换成度。45度是0.7853982弧度。。。但我们似乎添加了额外的步骤,只是为了迫使proble使用弧度,以便我们可以将其打印为度。如果我知道数字已经是45.0,那么有没有一种简单的方法来输出45度呢?@Adam您可以将包含答案的变量转换为字符串,然后与度符号连接。将abm转换为答案中所示的整数后,可以执行以下操作:
str(mbc)+'°
。通过这种方式,您将得到字符串“45°”,这与数字的度表示形式不太一样,是吗?@Adam同样适用于
math.degrees()
:它只进行转换,但并不表示python中的实际度。如您所述,如果在使用
math.degrees()
后打印学位,则不会添加“°”符号。您完全正确。我想这是一个不同的数字表示法。但我不知道为什么。我来自java背景,到目前为止python对我来说有点奇怪。