-1

请问有人可以帮我用Python吗?当我运行以下代码时,我得到两个L_AND的输出 1.0 L_1,但我希望它只是 1。

import math

d_ = 0          # My student number last digit
n_ = 10 + 0     # nth roots of unity

import math as m     # for real
import cmath as m    # for complex

# K_     [ number of the root]
K_ = 9
Root = m.exp((2 * K_ * m.pi * 1j) / n_)      # determine the nth root of unity by using exponential form
Root1 = math.cos((2 * K_ * m.pi / n_)) + 1j * math.sin((2 * K_ * m.pi / n_))   # determine the nth root of unity by using polar form
p_ = (Root) **  (n_)      # 10th power of Root
p_1 = (Root1) **  (n_)    # 10th power of Root1
L_ = (Root.real ** 2 + Root.imag ** 2)       # Test whether the point Root lies on unit circle
L_1 = (Root1.real ** 2 + Root1.imag ** 2)      # Test whether the point Root1 lies on unit circle

print  L_    
print  L_1
4

1 回答 1

0
print int(math.round(L_))

如果您想要更少的舍入,您可以使用可选的第二个round参数来指定多个位置。但是不要完全忽略它,否则 0.9999999 会变成 0。

如果您希望该值首先是整数,请在赋值时执行:

L_ = int(math.round((Root.real ** 2 + Root.imag ** 2), 6)
于 2013-01-31T01:23:54.917 回答