2 回答
TA贡献1858条经验 获得超8个赞
嗨 Ecuadorian_Programmer。如果将数字转换为字符串,则可以控制小数位的位置。例如:
import numpy as np # For take pi
a = str(np.pi) # We transform the number into a string
print(a.replace('.','')) # We delete the point decimal separator)
'3141592653589793'
如果你想在单独的行中打印 10 位 pi,这可以正常工作:
import numpy as np # For take pi
a = str(np.pi).replace('.','') # We transform the number into a string without the point decimal separator
for i in range(10):
print(a[i]) # Print all numbers in separated lines
而且,如果您只想打印小数(而不是最初的 3),您可以重新定义变量制作:
a=a.replace(a[0],'')
print(a) # Only decimals
'1415926558979'
TA贡献1785条经验 获得超8个赞
您只需要使用该print方法,为 pi 中的每个数字调用它。考虑以下代码:
from math import pi
strPiDigits = str(pi).replace(".", "")
for i in range(10):
print strPiDigits[i]
添加回答
举报
