-
Notifications
You must be signed in to change notification settings - Fork 3
solution m3-025 #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
solution m3-025 #179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
def check_card(dict_card): | ||
is_win = False | ||
# check columns | ||
for n_column in dict_card.values(): | ||
if is_win: | ||
break | ||
else: | ||
for c in n_column: | ||
if c == 0: | ||
is_win = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if is_win == true, why you don't break the loop? Moreover, |
||
else: | ||
is_win = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||
# check rows | ||
if not is_win: | ||
for i in range(len(dict_card.keys())): | ||
if is_win: | ||
break | ||
else: | ||
n_row = list(item[i] | ||
for item in dict_card.values()) | ||
for r in n_row: | ||
if r == 0: | ||
is_win = True | ||
else: | ||
is_win = False | ||
break | ||
# check diagonals | ||
if not is_win: | ||
diagonal_1 = dict_card['B'][0], dict_card['I'][1], dict_card['N'][2], dict_card['G'][3], dict_card['O'][4] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can do better with a loop? |
||
for d in diagonal_1: | ||
if d == 0: | ||
is_win = True | ||
else: | ||
is_win = False | ||
diagonal_2 = dict_card['B'][4], dict_card['I'][3], dict_card['N'][2], dict_card['G'][1], dict_card['O'][0] | ||
for d in diagonal_2: | ||
if d == 0: | ||
is_win = True | ||
else: | ||
is_win = False | ||
break | ||
break | ||
return is_win | ||
|
||
card_1 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try to generate the cards randomly using the random library? |
||
'B':[0,1,6,12,0], | ||
'I':[16,20,0,18,25], | ||
'N':[0,45,0,33,38], | ||
'G':[51,48,55,53,46], | ||
'O':[61,75,68,73,65] | ||
} | ||
|
||
card_2 = { | ||
'B':[0,0,0,0,0], | ||
'I':[16,20,0,18,25], | ||
'N':[0,45,0,33,38], | ||
'G':[51,48,55,53,46], | ||
'O':[61,75,68,73,65] | ||
} | ||
|
||
card_3 = { | ||
'B':[0,1,0,12,0], | ||
'I':[16,20,0,18,25], | ||
'N':[0,45,0,33,38], | ||
'G':[51,48,0,53,46], | ||
'O':[61,75,0,73,65] | ||
} | ||
|
||
card_4 = { | ||
'B':[0,1,6,12,0], | ||
'I':[16,20,0,0,25], | ||
'N':[0,45,0,33,38], | ||
'G':[51,0,55,53,46], | ||
'O':[0,75,68,73,65] | ||
} | ||
|
||
check_1 = check_card(card_1) | ||
check_2 = check_card(card_2) | ||
check_3 = check_card(card_3) | ||
check_4 = check_card(card_4) | ||
list_check = [check_1, check_2, check_3, check_4] | ||
|
||
for n_card in range(0,4): | ||
if list_check[n_card]: | ||
print(f'Card {n_card+1} is winner') | ||
else: | ||
print(f'Card {n_card+1} is loser') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?