偶数和平方数
那个数据.txt文件位于以下1000行中,数字范围为[0.999999]。你知道吗
(a)在a.txt文件中,在数据.txt文件的格式为:“偶数为[number of numbers]”//ivedoneit
(b)将文件中的所有数字复制到b.txt文件数据.txt,其中单位数等于7或0//ivedoneit
(c)把所有整数的平方复制到c.txt文件中,例如这个数字是225,因为
225=15**2个
我已经做完了
def main():
infile = open('dane.txt','r')
evenTotal = 0
oddTotal = 0
line = infile.readline()
while line != '':
if int(line) % 10 == 0 and int(line) % 7 == 0:
evenTotal += int(line)
even = open('a.txt', 'w')
even.write("wszystkie liczby jednosci ")
even.write(str(evenTotal))
else:
oddTotal += int(line)
line = infile.readline()
print('The total for the even numbers is',evenTotal)
print('The total for the odd numbers is',oddTotal)
infile.close()
print('All done!')
main()
这对我有好处,我只需要换衣服
if int(line) % 2 == 0:
它是有效的,但我完全不知道怎么做(c)。你知道吗
由Python: Check if a number is a perfect square协助
您应该运行:
在999999之间有有限个整数平方。您可以将一组介于0和999999之间的整数放在一起,然后为每一行检查该行的编号是否在此集合中。你知道吗
相关问题 更多 >
编程相关推荐