From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/5] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/5] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From b1e0c0593f21cb936e8a4d454cb571a635d214d5 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 15 Apr 2024 00:41:08 +0530 Subject: [PATCH 3/5] yacht --- .../yacht/__pycache__/yacht.cpython-39.pyc | Bin 0 -> 1128 bytes .../yacht_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 6786 bytes practice/yacht/yacht.py | 45 +++++++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 practice/yacht/__pycache__/yacht.cpython-39.pyc create mode 100644 practice/yacht/__pycache__/yacht_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/yacht/__pycache__/yacht.cpython-39.pyc b/practice/yacht/__pycache__/yacht.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..47f56d939c592023794bac8290f682695bc6d1e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cmV?d00001 diff --git a/practice/yacht/yacht.py b/practice/yacht/yacht.py index d64452f..1e5a7d7 100644 --- a/practice/yacht/yacht.py +++ b/practice/yacht/yacht.py @@ -1,18 +1,37 @@ # Score categories. # Change the values as you see fit. -YACHT = None -ONES = None -TWOS = None -THREES = None -FOURS = None -FIVES = None -SIXES = None -FULL_HOUSE = None -FOUR_OF_A_KIND = None -LITTLE_STRAIGHT = None -BIG_STRAIGHT = None -CHOICE = None +YACHT = 'YACHT' +ONES = 1 +TWOS = 2 +THREES = 3 +FOURS = 4 +FIVES = 5 +SIXES = 6 +FULL_HOUSE = 'FULL_HOUSE' +FOUR_OF_A_KIND = 'FOUR_OF_A_KIND' +LITTLE_STRAIGHT = 'LITTLE_STRAIGHT' +BIG_STRAIGHT = 'BIG_STRAIGHT' +CHOICE = 'CHOICE' def score(dice, category): - pass + if category in (1,2,3,4,5,6): + return dice.count(category) * category + elif category == 'FULL_HOUSE': + if len(set(dice)) == 2 and dice.count(dice[0]) in [2, 3]: + return sum(dice) or 0 + elif category == 'FOUR_OF_A_KIND': + if dice[0] == dice[3] or dice[1] == dice[4]: + return dice[1] * 4 or 0 + elif category == 'LITTLE_STRAIGHT': + if sorted(dice) == [1, 2, 3, 4, 5]: + return 30 or 0 + elif category == 'BIG_STRAIGHT': + if sorted(dice) == [2, 3, 4, 5, 6]: + return 30 or 0 + elif category == 'YACHT': + if all(num == dice[0] for num in dice): + return 50 + elif category == 'CHOICE': + return sum(dice) + return 0 From 242b0f74d7bc54f009a138691f507369abb181d8 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 03:07:59 +0530 Subject: [PATCH 4/5] removed cache files --- practice/yacht/__pycache__/yacht.cpython-39.pyc | Bin 1128 -> 0 bytes .../yacht_test.cpython-39-pytest-6.2.4.pyc | Bin 6786 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/yacht/__pycache__/yacht.cpython-39.pyc delete mode 100644 practice/yacht/__pycache__/yacht_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/yacht/__pycache__/yacht.cpython-39.pyc b/practice/yacht/__pycache__/yacht.cpython-39.pyc deleted file mode 100644 index 47f56d939c592023794bac8290f682695bc6d1e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1128 zcmZ`&%}*0S6rb6zZoi>41dLJiL@y1I#Di&wSPHE+ZNe7BO-)mGmP-1ub#_aD;0dBV z`X`77BcA;ujPWm+tEXO!i8oKaHye+l4n3G%R6Aww(=EQHqLAY2K^IL`k{|3M@d7gO< zQ-h8Y?Cmz8Ce*IgXXriQ1qDF?D(G3 zbPrta?D_rXkhh%xc+JDM^D+oAKRguCLdPAr2SdJc2Lk+tO^)V#$K!6k(DR&j&tJ)3 zQYQDn%o6}PL+Fk-8U#Y^xdWm4E=c~UFAU$~fy;#2?)9MH8Q==jX$Nk{HBp0HG#L!M-bTfo4FSqOnVyrH0h_ZQ#~&Nsf&aTD?}Xgw}Xkw}jCsZtoBRhZfYTDm)p?>0c zF^6A^1ZWT`YWWE3Xek!eB3db)Pej}&$$XNZbmTi;X%L0jM-5^|@?GlpSiTb?8(Jn_ z!?$Rw1(NC~iWhVEwf;e2@Gs<}5P|4NEgypz#8Jl~0ZG&e=ztXJBy>U=bq91oH|iAh zKriY}=z}w;)6frRQFp-r45IFaAs9y810yhsx);Xa9O^z8hY8eY;5e9_n$p4-ZgJ zz$`pOeI6dcW7L!I1fHV40MBq{o;#gy^}?Q=Gc3Ch!C9z(sGY>`0)DMY6u)VoG&}Ms zx{Jp6Gh#>H#r}vw^p7YR0bdkb%_M3G>?dQ*qIM7O9mbt5-Led6FaBKBi%#Nze%MJ^ zg^D!tiMR6$%eljd6Ss`w&Y>o|aLB*2FQ0C`-k4gbfU&h}RSH|i2SXN2tF*N*^@42{ zj4ghPD}{|LruPq=G&KZ2Avd$g&RXQx!3Nc7uS0m&G*vZb-A66@F?SN^f#f;qq!ux9 zMK`vbUdB+a90BdYdv&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vS=UCxrA zCAoY|;t2^_!^&qQo|B-Zp`0TzPr^Hn<`%C&>Fk;&$)cgDNGkSaf0EvlNjs_Ss#&zn zvgLHo?H^!PJ-Qkb`v>F))9(KR%u0D$8tDHoA0D)iSP>a4a8E gJE?I`jAIIOl+5i9m From 4a0f3ffa03f02e975c636efeb681ebe8c9174a71 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 15:54:45 +0530 Subject: [PATCH 5/5] improved the code --- practice/yacht/yacht.py | 54 ++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/practice/yacht/yacht.py b/practice/yacht/yacht.py index 1e5a7d7..7cd64f7 100644 --- a/practice/yacht/yacht.py +++ b/practice/yacht/yacht.py @@ -1,5 +1,4 @@ # Score categories. -# Change the values as you see fit. YACHT = 'YACHT' ONES = 1 TWOS = 2 @@ -15,23 +14,50 @@ def score(dice, category): - if category in (1,2,3,4,5,6): - return dice.count(category) * category - elif category == 'FULL_HOUSE': + """ + Calculate the score of a roll of dice in the game of Yacht. + + The game of Yacht is a dice game similar to Poker Dice, Generala and others. + The task is to score a throw according to these rules. + + Args: + dice (list): A list of five integers representing the dice roll. + category (str or int): The category in which the dice roll is to be scored. + + Returns: + int: The score of the dice roll in the given category. + + Examples: + >>> score([2, 3, 4, 5, 6], BIG_STRAIGHT) + 30 + >>> score([1, 1, 1, 1, 1], YACHT) + 50 + """ + # Check for categories that are scored by the number of dice showing the category number + if category in (ONES, TWOS, THREES, FOURS, FIVES, SIXES): + return dice.count(category) * category + # Check for full house + elif category == FULL_HOUSE: if len(set(dice)) == 2 and dice.count(dice[0]) in [2, 3]: - return sum(dice) or 0 - elif category == 'FOUR_OF_A_KIND': + return sum(dice) + # Check for four of a kind + elif category == FOUR_OF_A_KIND: if dice[0] == dice[3] or dice[1] == dice[4]: - return dice[1] * 4 or 0 - elif category == 'LITTLE_STRAIGHT': + return dice[1] * 4 + # Check for little straight + elif category == LITTLE_STRAIGHT: if sorted(dice) == [1, 2, 3, 4, 5]: - return 30 or 0 - elif category == 'BIG_STRAIGHT': + return 30 + # Check for big straight + elif category == BIG_STRAIGHT: if sorted(dice) == [2, 3, 4, 5, 6]: - return 30 or 0 - elif category == 'YACHT': + return 30 + # Check for yacht + elif category == YACHT: if all(num == dice[0] for num in dice): return 50 - elif category == 'CHOICE': + # Check for choice + elif category == CHOICE: return sum(dice) - return 0 + # If none of the above conditions are met, the score is 0 + return 0 \ No newline at end of file