皆様いつもお世話になっております。
乱数を出力して、一定時間ごとにテキストに改行しつつそれを書き込みたいのですが、改行されずに一行の文字列だけが出力されてしまって困っています。
どうしたら一行書き終えるごとに改行できるようになるのでしょうか?
ご指導とアドバイスのほどよろしくお願いします。
Python
1# coding:utf-8 2import random 3from time import sleep 4 5count = 0 6while True: 7 temprature = random.uniform(-40, 40) 8 print temprature 9 if temprature < 15: 10 print str(temprature) + "degree"+" It's cold now" 11 elif temprature >= 15 and temprature <= 25: 12 print str(temprature) + "degree"+" It's normal" 13 elif temprature > 25: 14 print str(temprature) + "degree"+" It's hot!!!" 15 sleep(3) 16 count += 1 17 if count > 4: 18 global count 19 print "count is 4!" 20 count = 0 21 f = open('data.csv', 'w') 22 f.write(str(temprature) + " 度\n") 23 f.close() 24 print "dataR is written to data.csv" 25 print "入力が終了しました。\n"
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/29 02:52