Python degrees

Python degrees 数学函数用于将给定角度从弧度转换为度。在本节中,我们将通过示例讨论如何使用 degrees 函数。

degrees 函数的语法如下所示。这里,参数可以是数字或有效的数值表达式。如果 number 参数是正数或负数,它将返回输出。如果它不是数字,它将返回 TypeError。

math.degrees(number);

Python degrees 函数示例

此数学函数将给定角度从弧度转换为度。在此示例中,我们将转换不同数据类型的弧度为度,并打印输出。

  1. 在前三个语句中,我们使用零、正整数和负整数值作为参数。
  2. 在接下来的两个语句中,我们使用 degrees 函数,并将正数和负数小数作为参数。
  3. 在接下来的两个 Python 语句中,我们将此 数学函数 用于 Tuple 和 List 的项。如您所见,它在它们上面工作正常。
  4. 接下来,我们尝试直接处理多个值。
  5. 接下来,我们使用了 Pi 的值。
  6. 最后,我们将其用于字符串值。正如我们之前所说,它会返回 TypeError 作为输出。
import math

Tup = (1, 2, 8, 4 , 5) # Tuple Declaration
Lis = [8, 3, 9, 5 , 7] # List Declaration

print('Calculating Degree of Zero = %.2f' %math.degrees(0))
print('Calculating Degree of Positive Integer = %.2f' %math.degrees(6))
print('Calculating Degree of Negative Integer = %.2f' %math.degrees(-12))

print('Calculating Degree of Positive Decimal = %.2f' %math.degrees(4.56))
print('Calculating Degree of Negative Decimal = %.2f' %math.degrees(-15.78))

print('Calculating Degree of Tuple Item = %.2f' %math.degrees(Tup[2]))
print('Calculating Degree of List Item = %.2f' %math.degrees(Lis[2]))

print('Calculating Degree of Multiple Numbers = %.2f' %math.degrees(10 + 20 - 25))

print('Calculating Degree of PIE = %.2f' %math.degrees(math.pi))
print('Calculating Degree of PIE/2 = %.2f' %math.degrees(math.pi/2))
print('Calculating Degree of PIE/4 = %.2f' %math.degrees(math.pi/4))
print('Calculating Degree of PIE/6 = %.2f' %math.degrees(math.pi/6))

print('Calculating Degree of String Value = ', math.degrees('3'))
math degrees Function