Even and square numbers
The data.txt file is located in the following lines of 1000 numbers from the range [0.999999].
(a) to the a.txt file, enter the number of even numbers in the data.txt file in the following form: "Even numbers are [number of numbers]" //ivedoneit
(b) to the b.txt file, copy all numbers from the file data.txt, in which the digit of unity is equal to 7 or 0//ivedoneit
(c) to the c.txt file, copy all numbers that are squares of integers, eg this number is the number 225, because
225 = 15**2
I've done already
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()
its good for (b) for (a) I have only to change for
if int(line) % 2 == 0:
and it works but I completely don't know how to do (c).