[Tutor] Problem solving
Sibylle Koczian
nulla.epistola at web.de
Wed Nov 18 06:33:43 EST 2020
Am 15.11.2020 um 13:15 schrieb Robin Williamson via Tutor:
> if b "or" v<r
> print("rouge"):
> elif v"or"r<b
> print("bleu")
> else:
> print("vert")I am trying to write a program that will tell me what the dominant colour is in a photo, either green, red or blue.I have tried to write the above program but it seems I have'nt understood something.Any help and explanations would be greatly appreciated.ThanksRobinYou may have noticed that I'm using rouge for red, vert for green, and bleu for blue, I'm in France!
>
In addition to Alan Gauld's answer: I think Python may interpret your
conditions not like you meant them - but perhaps I've misunderstood the
meaning of your variables b, r, v. Those names aren't good.
I read your variables like this:
b: quantity of blue in the photo
r: quantity of red
v: quantity of green (v for vert)
And I guess that your first condition should tell Python:
If there is less blue or green than red in the photo, then print
"rouge". Or, nearer to logic and programming: if there is less blue than
red *and* less green than red, then print "rouge".
But if you change your string "or" to the keyword or, then Python reads
it like this:
if b or (v < r)
which means: if there is any blue at all in the photo, then print
"rouge"; if there is less green than red, then print "rouge".
So I suppose your first condition should be
if b < r and v < r:
print("rouge")
HTH
Sibylle
More information about the Tutor
mailing list