線形合同法(Park & Miller)を実装しているのですが、外部ファイルに作っている数列を取り込んで次の項を計算しようとすると、次のエラーが出ます。
python
1import numpy as np 2import linecache 3 4M = (2**31)-1 5a = 16807 6x_0 = 1 7 8with open('lcg.txt', 'w') as f: 9 f.write("{}".format(x_0)) 10 11with open('lcg.txt') as f: 12 print(f.read()) 13 14 15for i in range(1, 2*M+10, 1): 16 l = linecache.getline('lcg.txt', i) 17 ll = int(l) 18 x = (a*ll)%M 19 20 with open('lcg.txt', 'a') as f: 21 f.write('{}\n'.format(x)) 22 23 24with open('lcg.txt', r) as f: 25 print(f.read()) 26
エラー invalid literal for int() with base 10: ''
type(l)=strで、type(ll)=intなので、問題なく動くと思ったのですが、エラーが出てしまいました。色々int()等の使い方は調べたのですが特に間違えてはないと思います。何か分かる方はご教授ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/25 13:19