整数的平方数

2024-09-29 23:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

偶数和平方数

那个数据.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)。你知道吗


Tags: 文件数据txtmainline数字infileint

热门问题