+ 1
Scoring a three-of-a-kind
This is continuing my first little Python project. I've got it to score ones and fives correctly. I've tried several versions of syntax trying to get it to recognize a three-of-a-kind. No errors, strangely, but tends to score each instance instead of the set of three. def keep_score(throw_choice): score = 0 for i in (throw_choice): if i == [1]*3: score += 1000 if i == [2]*3: score += 200 https://code.sololearn.com/cGXTStr95INy/?ref=app
3 Antworten
+ 1
the statement 'for i in (throw_choice):' enumerate only 1 item at a time, which is an integer. so it will never match [1]*3, which is [1, 1, 1]
Do not use the for loop and try below:
if [1]*3 in throw_choice:
score += 1000
if [2]*3 in throw_choice:
score += 200
...
+ 1
Thank you Lindsay! Super helpful! I finally got my account authenticated so I can give you a well deserved upvote! 😃
+ 1
lol.Thank you Paul!