任务是我们必须编写一个程序来显示 pi 的前 10 位数字。每个数字应每行显示一个,末尾没有句号。我理解整个导入语句,但我在 for 循环中有很多错误。
繁花如伊
浏览 136回答 2
2回答
猛跑小猪
嗨 Ecuadorian_Programmer。如果将数字转换为字符串,则可以控制小数位的位置。例如:import numpy as np # For take pia = 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 pia = str(np.pi).replace('.','') # We transform the number into a string without the point decimal separatorfor i in range(10): print(a[i]) # Print all numbers in separated lines而且,如果您只想打印小数(而不是最初的 3),您可以重新定义变量制作:a=a.replace(a[0],'')print(a) # Only decimals'1415926558979'