ООП 24 / std.nums

ru en cn

с начала прошло: 70 д. 05:47
страница обновлена: 2025-12-15 04:29:05.630368+00

std.nums: nums.py

import sys

OK = 0
PE = 1
WA = 2
UH = 3

if len(sys.argv) < 4:
    print("Too few arguments for testing script")
    exit(UH)

input_file = sys.argv[1]
output_file = sys.argv[2]
answer_file = sys.argv[3]

try:
    with open(output_file) as f:
        output_data = list(map(int, f.read().split()))
except:
    print("Wrong answer format")
    exit(PE)

try:
    with open(answer_file) as f:
        answer_data = list(map(int, f.read().split()))
except:
    print("Failed to parse answer file")
    exit(UH)

if len(output_data) < len(answer_data):
    print('Too few numbers')
    exit(PE)

if len(output_data) > len(answer_data):
    print('Extra numbers')
    exit(PE)

for (n, (i, j)) in enumerate(zip(output_data, answer_data)):
    if i != j:
        print(f'{i} instead of {j} in pos {n}', end='')
        
exit(0)
Дальневосточный федеральный университет