Before working on an image, check its size and how bright it is.
What to build
A program that reports an image's size, darkest and brightest values, mean brightness and where the brightest pixel is.
Requirements
- Print
size H x W, thendarkest A, brightest B, thenmean Mwith two decimal places. - Then print
brightest pixel at row R, column C: the first pixel with the largest value in reading order (row by row, left to right).
Input
Line 1: the height H and width W. Then H lines of W whole numbers from 0 to 255.
Output
Four lines.
Constraints
1 ≤ H, W ≤ 100.
Example
Input:
2 3
10 20 30
40 50 60
Output:
size 2 x 3
darkest 10, brightest 60
mean 35.00
brightest pixel at row 1, column 2
Why it works
The size, range and mean summarise an image in a few numbers; reading order makes "the first brightest pixel" well defined when several pixels share the maximum.
Examples
2 3 10 20 30 40 50 60
size 2 x 3 darkest 10, brightest 60 mean 35.00 brightest pixel at row 1, column 2
3 3 0 255 0 255 0 255 0 255 0
size 3 x 3 darkest 0, brightest 255 mean 113.33 brightest pixel at row 0, column 1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Collect every value into one list with a comprehension, then use min, max and sum.
Hint 2
For the brightest pixel, scan the rows in order and stop at the first row that contains the maximum; `row.index(top)` gives its column.
Solution
Show one correct solution (try it yourself first)
h, w = map(int, input().split())
img = [list(map(int, input().split())) for _ in range(h)]
values = [v for row in img for v in row]
top = max(values)
print(f"size {h} x {w}")
print(f"darkest {min(values)}, brightest {top}")
print(f"mean {sum(values) / len(values):.2f}")
for r in range(h):
if top in img[r]:
print(f"brightest pixel at row {r}, column {img[r].index(top)}")
break