From fa013fb85570beba08c5888c588ae4d63aa57487 Mon Sep 17 00:00:00 2001 From: Praveen Date: Fri, 15 Mar 2024 18:39:57 +0530 Subject: [PATCH 1/4] Added test file for is_number --- very_easy/is_number.py | 1 + very_easy/test_is_number.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 very_easy/test_is_number.py diff --git a/very_easy/is_number.py b/very_easy/is_number.py index 5dcd98f9eb1..29654794bbf 100644 --- a/very_easy/is_number.py +++ b/very_easy/is_number.py @@ -31,3 +31,4 @@ def check_number(input_value: Any) -> str: print(check_number(pow(10, 20))) print(check_number("Hello")) print(check_number(1 + 2j)) + diff --git a/very_easy/test_is_number.py b/very_easy/test_is_number.py new file mode 100644 index 00000000000..4a16da78794 --- /dev/null +++ b/very_easy/test_is_number.py @@ -0,0 +1,23 @@ +import pytest + +from is_number import check_number + +def test_check_number_float(): + assert check_number(3.14) == '3.14 is a number.' + assert check_number(1e-5) == '1e-05 is a number.' + +def test_check_number_negative_float(): + assert check_number(-3.14) == '-3.14 is a number.' + assert check_number(-1e-5) == '-1e-05 is a number.' + +def test_check_number_boolean(): + assert check_number(True) == 'True is a number.' + assert check_number(False) == 'False is a number.' + +def test_check_number_list(): + assert check_number([1, 2, 3]) == '[1, 2, 3] is not a number.' + assert check_number([]) == '[] is not a number.' + +def test_check_number_dict(): + assert check_number({'key': 'value'}) == "{'key': 'value'} is not a number." + assert check_number({}) == "{} is not a number." From caff276912622e64b7a7d00308afb52be5c721d5 Mon Sep 17 00:00:00 2001 From: Praveen Date: Sat, 16 Mar 2024 11:36:41 +0530 Subject: [PATCH 2/4] Added visual representation of board --- BoardGame-CLI/snakeLadder/snakeLadder.py | 209 ++++++++++++++++++ .../snakeLadder/styled_df_output.html | 158 +++++++++++++ 2 files changed, 367 insertions(+) create mode 100644 BoardGame-CLI/snakeLadder/snakeLadder.py create mode 100644 BoardGame-CLI/snakeLadder/styled_df_output.html diff --git a/BoardGame-CLI/snakeLadder/snakeLadder.py b/BoardGame-CLI/snakeLadder/snakeLadder.py new file mode 100644 index 00000000000..6a7cdab69e2 --- /dev/null +++ b/BoardGame-CLI/snakeLadder/snakeLadder.py @@ -0,0 +1,209 @@ +import random +import pandas as pd +from IPython.display import display + +# Taking players data +players = {} # stores players name their locations +isReady = {} +current_loc = 1 # vaiable for iterating location + +# creating board +board = [ + [100, 99, 98, "S", 96, "S", 94, 93, 92, 91], + [81, 82, 83, 84, 85, 86, "L", "S", 89, 90], + [80, 79, 78, 77, 76, 75, 74, 73, 72, "L"], + [61, 62, "S", 64, 65, 66, 67, 68, 69, 70], + [60, 59, 58, 57, 56, 55, 54, 53, 52, 51], + [41, 42, 43, 44, 45, 46, 47, "S", 49, "L"], + ["L", 39, 38, 37, "S", 35, 34, 33, "S", 31], + [21, 22, 23, 24, 25, 26, 27, "L", 29, 30], + ["L", 19, 18, 17, 16, 15, 14, 13, 12, 11], + [1, 2, 3, "L", 5, 6, 7, "L", 9, 10], +] + +df = pd.DataFrame(board) + +styled_df = df.style \ + .set_properties(**{'background-color': 'lightblue', 'color': 'black'}) \ + .set_table_styles([{ + 'selector': 'td', + 'props': [ + ('padding', '20px'), + ] + }]) + +# DataFrame as HTML +html_output = styled_df.render() + +# Save the HTML output +with open('styled_df_output.html', 'w') as f: + f.write(html_output) + +print("HTML output saved to 'styled_df_output.html'") + +imp = True + +# players input function +def player_input(): + global players + global current_loc + global isReady + + x = True + while x: + player_num = int(input("Enter the number of players: ")) + if player_num > 0: + for i in range(player_num): + name = input(f"Enter player {i+1} name: ") + players[name] = current_loc + isReady[name] = False + x = False + play() # play funtion call + + else: + print("Number of player cannot be zero") + print() + + +# Dice roll method +def roll(): + # print(players) + return random.randrange(1, 7) + + +# play method +def play(): + global players + global isReady + global imp + + print("/"*20) + print("1 -> roll the dice (or enter)") + print("2 -> start new game") + print("3 -> exit the game") + print("/"*20) + + while imp: + for i in players: + n = input("{}'s turn: ".format(i)) or 1 + n = int(n) + + if players[i] < 100: + if n == 1: + temp1 = roll() + print(f"you got {temp1}") + print("") + + if isReady[i] == False and temp1 == 6: + isReady[i] = True + + if isReady[i]: + looproll = temp1 + counter_6 = 0 + while looproll == 6: + counter_6 += 1 + looproll = roll() + temp1 += looproll + print(f"you got {looproll} ") + if counter_6 == 3 : + temp1 -= 18 + print("Three consectutives 6 got cancelled") + print("") + # print(temp1) + if (players[i] + temp1) > 100: + pass + elif (players[i] + temp1) < 100: + players[i] += temp1 + players[i] = move(players[i], i) + elif (players[i] + temp1) == 100: + print(f"congrats {i} you won !!!") + imp = False + return + + print(f"you are at position {players[i]}") + print('-'*20) + + elif n == 2: + players = {} # stores player ans their locations + isReady = {} + current_loc = 0 # vaiable for iterating location + player_input() + + elif n == 3: + print("Bye Bye") + imp = False + + else: + print("pls enter a valid input") + + +# Move method +def move(a, i): + global players + global imp + temp_loc = players[i] + + if (temp_loc) < 100: + temp_loc = ladder(temp_loc, i) + temp_loc = snake(temp_loc, i) + + return temp_loc + + +# snake bite code +def snake(c, i): + if (c == 32): + players[i] = 10 + elif (c == 36): + players[i] = 6 + elif (c == 48): + players[i] = 26 + elif (c == 63): + players[i] = 18 + elif (c == 88): + players[i] = 24 + elif (c == 95): + players[i] = 56 + elif (c == 97): + players[i] = 78 + else: + return players[i] + print(f"You got bitten by a snake now you are at {players[i]}") + + return players[i] + + +# ladder code +def ladder(a, i): + global players + + if (a == 4): + players[i] = 14 + elif (a == 8): + players[i] = 30 + elif (a == 20): + players[i] = 38 + elif (a == 40): + players[i] = 42 + elif (a == 28): + players[i] = 76 + elif (a == 50): + players[i] = 67 + elif (a == 71): + players[i] = 92 + elif (a == 87): + players[i] = 99 + else: + return players[i] + print(f"You got a ladder now you are at {players[i]}") + + return players[i] + + +# while run: +print("/"*40) +print("Welcome to the snake ladder game !!!!!!!") +print("/"*40) + + +player_input() \ No newline at end of file diff --git a/BoardGame-CLI/snakeLadder/styled_df_output.html b/BoardGame-CLI/snakeLadder/styled_df_output.html new file mode 100644 index 00000000000..a9f116fa744 --- /dev/null +++ b/BoardGame-CLI/snakeLadder/styled_df_output.html @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 0123456789
01009998S96S94939291
1818283848586LS8990
2807978777675747372L
36162S64656667686970
460595857565554535251
541424344454647S49L
6L393837S353433S31
721222324252627L2930
8L191817161514131211
9123L567L910
From 3c463fc8dce300c818bfb54d438ab3c3ca3d1b68 Mon Sep 17 00:00:00 2001 From: Praveen Date: Sat, 16 Mar 2024 11:39:31 +0530 Subject: [PATCH 3/4] Added visual representation of board --- BoardGame-CLI/snakeLadder/snakeLadder.py | 1 - .../snakeLadder/styled_df_output.html | 246 +++++++++--------- 2 files changed, 123 insertions(+), 124 deletions(-) diff --git a/BoardGame-CLI/snakeLadder/snakeLadder.py b/BoardGame-CLI/snakeLadder/snakeLadder.py index 6a7cdab69e2..bb91e516b8f 100644 --- a/BoardGame-CLI/snakeLadder/snakeLadder.py +++ b/BoardGame-CLI/snakeLadder/snakeLadder.py @@ -1,6 +1,5 @@ import random import pandas as pd -from IPython.display import display # Taking players data players = {} # stores players name their locations diff --git a/BoardGame-CLI/snakeLadder/styled_df_output.html b/BoardGame-CLI/snakeLadder/styled_df_output.html index a9f116fa744..68c27256bbb 100644 --- a/BoardGame-CLI/snakeLadder/styled_df_output.html +++ b/BoardGame-CLI/snakeLadder/styled_df_output.html @@ -1,158 +1,158 @@ - +
- - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + +
 01234567890123456789
01009998S96S9493929101009998S96S94939291
1818283848586LS89901818283848586LS8990
2807978777675747372L2807978777675747372L
36162S6465666768697036162S64656667686970
460595857565554535251460595857565554535251
541424344454647S49L541424344454647S49L
6L393837S353433S316L393837S353433S31
721222324252627L2930721222324252627L2930
8L1918171615141312118L191817161514131211
9123L567L9109123L567L910
From 5b4fea60e2fde6d59644875184c4d49b2e97969b Mon Sep 17 00:00:00 2001 From: Praveen Date: Sat, 16 Mar 2024 11:45:37 +0530 Subject: [PATCH 4/4] Added visual representation of the board --- BoardGame-CLI/snakeLadder.py | 53 ++++- BoardGame-CLI/snakeLadder/snakeLadder.py | 208 ------------------ .../{snakeLadder => }/styled_df_output.html | 0 3 files changed, 44 insertions(+), 217 deletions(-) delete mode 100644 BoardGame-CLI/snakeLadder/snakeLadder.py rename BoardGame-CLI/{snakeLadder => }/styled_df_output.html (100%) diff --git a/BoardGame-CLI/snakeLadder.py b/BoardGame-CLI/snakeLadder.py index d8892ed4339..bb91e516b8f 100644 --- a/BoardGame-CLI/snakeLadder.py +++ b/BoardGame-CLI/snakeLadder.py @@ -1,12 +1,46 @@ import random +import pandas as pd # Taking players data players = {} # stores players name their locations isReady = {} current_loc = 1 # vaiable for iterating location -imp = True +# creating board +board = [ + [100, 99, 98, "S", 96, "S", 94, 93, 92, 91], + [81, 82, 83, 84, 85, 86, "L", "S", 89, 90], + [80, 79, 78, 77, 76, 75, 74, 73, 72, "L"], + [61, 62, "S", 64, 65, 66, 67, 68, 69, 70], + [60, 59, 58, 57, 56, 55, 54, 53, 52, 51], + [41, 42, 43, 44, 45, 46, 47, "S", 49, "L"], + ["L", 39, 38, 37, "S", 35, 34, 33, "S", 31], + [21, 22, 23, 24, 25, 26, 27, "L", 29, 30], + ["L", 19, 18, 17, 16, 15, 14, 13, 12, 11], + [1, 2, 3, "L", 5, 6, 7, "L", 9, 10], +] + +df = pd.DataFrame(board) + +styled_df = df.style \ + .set_properties(**{'background-color': 'lightblue', 'color': 'black'}) \ + .set_table_styles([{ + 'selector': 'td', + 'props': [ + ('padding', '20px'), + ] + }]) + +# DataFrame as HTML +html_output = styled_df.render() + +# Save the HTML output +with open('styled_df_output.html', 'w') as f: + f.write(html_output) + +print("HTML output saved to 'styled_df_output.html'") +imp = True # players input function def player_input(): @@ -42,13 +76,13 @@ def play(): global isReady global imp - while imp: - print("/"*20) - print("1 -> roll the dice (or enter)") - print("2 -> start new game") - print("3 -> exit the game") - print("/"*20) + print("/"*20) + print("1 -> roll the dice (or enter)") + print("2 -> start new game") + print("3 -> exit the game") + print("/"*20) + while imp: for i in players: n = input("{}'s turn: ".format(i)) or 1 n = int(n) @@ -86,6 +120,7 @@ def play(): return print(f"you are at position {players[i]}") + print('-'*20) elif n == 2: players = {} # stores player ans their locations @@ -155,7 +190,7 @@ def ladder(a, i): players[i] = 67 elif (a == 71): players[i] = 92 - elif (a == 88): + elif (a == 87): players[i] = 99 else: return players[i] @@ -170,4 +205,4 @@ def ladder(a, i): print("/"*40) -player_input() +player_input() \ No newline at end of file diff --git a/BoardGame-CLI/snakeLadder/snakeLadder.py b/BoardGame-CLI/snakeLadder/snakeLadder.py deleted file mode 100644 index bb91e516b8f..00000000000 --- a/BoardGame-CLI/snakeLadder/snakeLadder.py +++ /dev/null @@ -1,208 +0,0 @@ -import random -import pandas as pd - -# Taking players data -players = {} # stores players name their locations -isReady = {} -current_loc = 1 # vaiable for iterating location - -# creating board -board = [ - [100, 99, 98, "S", 96, "S", 94, 93, 92, 91], - [81, 82, 83, 84, 85, 86, "L", "S", 89, 90], - [80, 79, 78, 77, 76, 75, 74, 73, 72, "L"], - [61, 62, "S", 64, 65, 66, 67, 68, 69, 70], - [60, 59, 58, 57, 56, 55, 54, 53, 52, 51], - [41, 42, 43, 44, 45, 46, 47, "S", 49, "L"], - ["L", 39, 38, 37, "S", 35, 34, 33, "S", 31], - [21, 22, 23, 24, 25, 26, 27, "L", 29, 30], - ["L", 19, 18, 17, 16, 15, 14, 13, 12, 11], - [1, 2, 3, "L", 5, 6, 7, "L", 9, 10], -] - -df = pd.DataFrame(board) - -styled_df = df.style \ - .set_properties(**{'background-color': 'lightblue', 'color': 'black'}) \ - .set_table_styles([{ - 'selector': 'td', - 'props': [ - ('padding', '20px'), - ] - }]) - -# DataFrame as HTML -html_output = styled_df.render() - -# Save the HTML output -with open('styled_df_output.html', 'w') as f: - f.write(html_output) - -print("HTML output saved to 'styled_df_output.html'") - -imp = True - -# players input function -def player_input(): - global players - global current_loc - global isReady - - x = True - while x: - player_num = int(input("Enter the number of players: ")) - if player_num > 0: - for i in range(player_num): - name = input(f"Enter player {i+1} name: ") - players[name] = current_loc - isReady[name] = False - x = False - play() # play funtion call - - else: - print("Number of player cannot be zero") - print() - - -# Dice roll method -def roll(): - # print(players) - return random.randrange(1, 7) - - -# play method -def play(): - global players - global isReady - global imp - - print("/"*20) - print("1 -> roll the dice (or enter)") - print("2 -> start new game") - print("3 -> exit the game") - print("/"*20) - - while imp: - for i in players: - n = input("{}'s turn: ".format(i)) or 1 - n = int(n) - - if players[i] < 100: - if n == 1: - temp1 = roll() - print(f"you got {temp1}") - print("") - - if isReady[i] == False and temp1 == 6: - isReady[i] = True - - if isReady[i]: - looproll = temp1 - counter_6 = 0 - while looproll == 6: - counter_6 += 1 - looproll = roll() - temp1 += looproll - print(f"you got {looproll} ") - if counter_6 == 3 : - temp1 -= 18 - print("Three consectutives 6 got cancelled") - print("") - # print(temp1) - if (players[i] + temp1) > 100: - pass - elif (players[i] + temp1) < 100: - players[i] += temp1 - players[i] = move(players[i], i) - elif (players[i] + temp1) == 100: - print(f"congrats {i} you won !!!") - imp = False - return - - print(f"you are at position {players[i]}") - print('-'*20) - - elif n == 2: - players = {} # stores player ans their locations - isReady = {} - current_loc = 0 # vaiable for iterating location - player_input() - - elif n == 3: - print("Bye Bye") - imp = False - - else: - print("pls enter a valid input") - - -# Move method -def move(a, i): - global players - global imp - temp_loc = players[i] - - if (temp_loc) < 100: - temp_loc = ladder(temp_loc, i) - temp_loc = snake(temp_loc, i) - - return temp_loc - - -# snake bite code -def snake(c, i): - if (c == 32): - players[i] = 10 - elif (c == 36): - players[i] = 6 - elif (c == 48): - players[i] = 26 - elif (c == 63): - players[i] = 18 - elif (c == 88): - players[i] = 24 - elif (c == 95): - players[i] = 56 - elif (c == 97): - players[i] = 78 - else: - return players[i] - print(f"You got bitten by a snake now you are at {players[i]}") - - return players[i] - - -# ladder code -def ladder(a, i): - global players - - if (a == 4): - players[i] = 14 - elif (a == 8): - players[i] = 30 - elif (a == 20): - players[i] = 38 - elif (a == 40): - players[i] = 42 - elif (a == 28): - players[i] = 76 - elif (a == 50): - players[i] = 67 - elif (a == 71): - players[i] = 92 - elif (a == 87): - players[i] = 99 - else: - return players[i] - print(f"You got a ladder now you are at {players[i]}") - - return players[i] - - -# while run: -print("/"*40) -print("Welcome to the snake ladder game !!!!!!!") -print("/"*40) - - -player_input() \ No newline at end of file diff --git a/BoardGame-CLI/snakeLadder/styled_df_output.html b/BoardGame-CLI/styled_df_output.html similarity index 100% rename from BoardGame-CLI/snakeLadder/styled_df_output.html rename to BoardGame-CLI/styled_df_output.html