小编nur*_*ri_的帖子

学习浮点数长度

有没有类似len()测量浮点数长度的命令?

当我尝试时:len(a[k]) (a[k] 是数组,它给出随机浮点数)

有如下错误:

object of type 'float' has no len()
Run Code Online (Sandbox Code Playgroud)

我的代码:

import random
a=[random.uniform(10,100) for i in range (1000)]

c= open("dosya.txt","w")
c.write('X DEGER:  Y DEGER:\n')
c.write('--------------\n')

count = 0.0
while count < 99.9:
count +=0.1
c.write ("%s\n" % count)    


c=open("dosya.txt","w")
c.seek(37,0)
for k in range(900):
    print a[k]
    c.write(", %.2f" %(a[k]))
    c.seek(len(str(a[k])),1)    
    c.close
Run Code Online (Sandbox Code Playgroud)

我想在文件中创建两列,但第二列循环数字,在第一列上写入。

例如,

 0.1  38.582   
 0.2  58.214                        
 0.3  16.427  

                
Run Code Online (Sandbox Code Playgroud)

但输出是这样的:

 0.1 38.585
 0.3 25.420 
 0.5 47.543
Run Code Online (Sandbox Code Playgroud)

正如您所看到的浮点数覆盖0.2

python command

2
推荐指数
1
解决办法
3万
查看次数

在File命令Python中添加循环

ı想创建一个文件,如:

X值:

1
2
3
4
5
.
.
.
999
Run Code Online (Sandbox Code Playgroud)

做那个ı写了那个命令但是;

错误,如:argument 1 must be string or read-only character buffer, not float,,

from numpy import *

c = open("text.txt","w")
count = 0
while (count < 100):
   print  count
   count = count + 0.1
   c.write (count)
   c.close
Run Code Online (Sandbox Code Playgroud)

python loops file

1
推荐指数
1
解决办法
83
查看次数

标签 统计

python ×2

command ×1

file ×1

loops ×1