Saya ingin membahagikan siri masa kepada keadaan Nilai maksimum siri masa ialah 1.8 dan nilai minimum ialah -0.5 Ia dibahagikan kepada 115 selang keadaan selang ditukar kepada nilai di tengah selang Saya menulis sekeping kod, tetapi bilangan tempat perpuluhan dalam nilai yang diperolehi adalah sangat pelik, tolong bantu saya menyelesaikan masalah, terima kasih
.__author__ = 'Administrator' file = open('yij.txt','r') while 1: line = file.readline() a = line.split() m=0 b=[-0.5,-0.48,-0.46,-0.44,-0.42,-0.40,-0.38,-0.36,-0.34,-0.32,-0.30,-0.28,-0.26,-0.24,-0.22,-0.20,-0.18,-0.16,-0.14,-0.12,-0.10,-0.08,-0.06,-0.04,-0.02,0.00,0.02, 0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26,0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.50,0.52,0.54,0.56,0.58,0.60,0.62,0.64, 0.66,0.68,0.70,0.72,0.74,0.76,0.78,0.80,0.82,0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98,1.00,1.02,1.04,1.06,1.08,1.10,1.12,1.14,1.16,1.18,1.20,1.22,1.24,1.26,1.28, 1.30,1.32,1.34,1.36,1.38,1.40,1.42,1.44,1.46,1.48,1.50,1.52,1.54,1.56,1.58,1.60,1.62,1.64,1.66,1.68,1.70,1.72,1.74,1.76,1.78,1.80] if line != '': file1 = open('yij_state.txt', 'a+') for i in b: if i1.8: file1.write("%.2f\n" % (1.79)) break file1.close else: break file.close
Kod telah diperbetulkan
Cukup simpan dua tempat perpuluhan