Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.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 将数字打印为整数(无小数)_Python_Python 2.7_Python 2.x - Fatal编程技术网

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

Python 将数字打印为整数(无小数),python,python-2.7,python-2.x,Python,Python 2.7,Python 2.x,有谁能帮我学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_ =

有谁能帮我学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
如果希望减少舍入,可以使用可选的second
round
参数指定多个位置。但不要完全忽略它,否则0.9999999将变为0

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

L_ = int(math.round((Root.real ** 2 + Root.imag ** 2), 6)

你认为所有这些
\uuu
使代码更容易阅读吗?实际上,我只想在打印复数L_u=(Root.real**2+Root.imag**2)的代码时得到1(整数)的输出
L_ = int(math.round((Root.real ** 2 + Root.imag ** 2), 6)