26 lines
698 B
Python
26 lines
698 B
Python
input = """123 328 51 64
|
|
45 64 387 23
|
|
6 98 215 314
|
|
* + * + """
|
|
# with open("input.txt", "r") as file:
|
|
# input = file.read()
|
|
# for row in input.splitlines():
|
|
# print(row)
|
|
# print("="*100)
|
|
numbers = [list(map(int, row.strip().split())) for row in input.splitlines()[:-1]]
|
|
operators = input.splitlines()[-1].strip().split()
|
|
result = [row for row in numbers[0]]
|
|
for row in numbers[1:]:
|
|
for index in range(len(result)):
|
|
element = row[index]
|
|
op = operators[index]
|
|
if op == "*":
|
|
result[index] *= element
|
|
elif op == "+":
|
|
result[index] += element
|
|
count = 0
|
|
for row in result:
|
|
count += row
|
|
print(result)
|
|
print(count)
|