Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1.1
- def if_arithmetic(array):
- difference = int(array[1]) - int(array[0])
- for index in range(len(array) - 1):
- if not (int(array[index + 1]) - int(array[index]) == difference):
- return False
- return True
- def count_difference(array):
- return int(array[1]) - int(array[0])
- how_many_arithmetic = 0
- differences = []
- with open("ciagi.txt") as file, open("wynik1.txt", "w") as result:
- lines = file.readlines()
- for line in lines:
- list_line = line.strip('\n').split(' ')
- if len(list_line) < 3:
- continue
- if if_arithmetic(list_line):
- how_many_arithmetic = how_many_arithmetic + 1
- differences.append(count_difference(list_line))
- result.write(f"In this file we have {how_many_arithmetic} arithmetic seq.\n")
- result.write(f"The max of diff: {max(differences)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement