将数字打印为整数(无小数)

2024-05-18 09:09:34 发布

您现在位置:Python中文网/ 问答频道 /正文

有谁能帮我学Python吗?当我运行以下代码时,L_L_1的输出都是1.0,但我希望它只有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

Tags: oftheimportnumberforaspimath
1条回答
网友
1楼 · 发布于 2024-05-18 09:09:34
print int(math.round(L_))

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

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

^{pr2}$

相关问题 更多 >