Skip to content

Commit 98b89e7

Browse files
Merge branch 'main' into redesign-ui
2 parents 23cdd79 + e0c1793 commit 98b89e7

16 files changed

Lines changed: 489 additions & 253 deletions

File tree

.github/workflows/python-ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Python CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Syntax check with py_compile
26+
run: |
27+
find . -name "*.py" -exec python -m py_compile {} +
28+
29+
- name: Run automated tests
30+
run: |
31+
python -m unittest discover -s tests -v

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,27 @@ These tasks are beginner-friendly and help you understand the project structure,
447447

448448
Once you feel comfortable, you can gradually try `level:intermediate`, `level:advanced`, and `level:critical` tasks.
449449

450+
## 🧪 Writing Tests
451+
452+
To maintain code quality and ensure zero external dependencies, we use the standard library's `unittest` framework.
453+
454+
1. **Test Directory**: All tests must be placed in the `tests/` directory at the root of the project.
455+
2. **File Naming**: Name your test file starting with `test_` (e.g., `test_armstrong.py`).
456+
3. **No External Modules**: Do not use external libraries like `pytest`. Stick strictly to `unittest`.
457+
4. **Mocking Inputs**: For CLI projects, use `subprocess` to provide input via `stdin`, or import helper methods directly.
458+
459+
### Running Tests Locally
460+
To run all tests and verify your changes:
461+
```bash
462+
python -m unittest discover -s tests -v
463+
```
464+
To run a syntax check across all files (similar to our CI):
465+
```bash
466+
find . -name "*.py" -exec python -m py_compile {} +
467+
```
468+
469+
---
470+
450471
## 🤔 Questions?
451472

452473
- 💬 Open an issue for questions

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,12 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
504504
</td>
505505
</tr>
506506
<tr>
507+
<td align="center" width="120">
508+
<a href="https://github.com/bhavyapandiya29">
509+
<img src="https://github.com/bhavyapandiya29.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="bhavyapandiya29" /><br />
510+
<sub><b>@bhavyapandiya29</b></sub>
511+
</a>
512+
</td>
507513
<td align="center" width="120">
508514
<a href="https://github.com/codewithakshyaaa">
509515
<img src="https://github.com/codewithakshyaaa.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="codewithakshyaaa" /><br />
@@ -534,14 +540,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
534540
<sub><b>@iamprasoon2006-cell</b></sub>
535541
</a>
536542
</td>
543+
</tr>
544+
<tr>
537545
<td align="center" width="120">
538546
<a href="https://github.com/itsdakshjain">
539547
<img src="https://github.com/itsdakshjain.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="itsdakshjain" /><br />
540548
<sub><b>@itsdakshjain</b></sub>
541549
</a>
542550
</td>
543-
</tr>
544-
<tr>
545551
<td align="center" width="120">
546552
<a href="https://github.com/jeetrouth">
547553
<img src="https://github.com/jeetrouth.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="jeetrouth" /><br />
@@ -572,14 +578,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
572578
<sub><b>@mahi-8758</b></sub>
573579
</a>
574580
</td>
581+
</tr>
582+
<tr>
575583
<td align="center" width="120">
576584
<a href="https://github.com/mrinmoyChakraborty-mrinox">
577585
<img src="https://github.com/mrinmoyChakraborty-mrinox.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="mrinmoyChakraborty-mrinox" /><br />
578586
<sub><b>@mrinmoyChakraborty-mrinox</b></sub>
579587
</a>
580588
</td>
581-
</tr>
582-
<tr>
583589
<td align="center" width="120">
584590
<a href="https://github.com/n1o5">
585591
<img src="https://github.com/n1o5.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="n1o5" /><br />
@@ -610,14 +616,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
610616
<sub><b>@parasmani-dev</b></sub>
611617
</a>
612618
</td>
619+
</tr>
620+
<tr>
613621
<td align="center" width="120">
614622
<a href="https://github.com/parulpaliwal01">
615623
<img src="https://github.com/parulpaliwal01.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="parulpaliwal01" /><br />
616624
<sub><b>@parulpaliwal01</b></sub>
617625
</a>
618626
</td>
619-
</tr>
620-
<tr>
621627
<td align="center" width="120">
622628
<a href="https://github.com/pragya-manna">
623629
<img src="https://github.com/pragya-manna.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="pragya-manna" /><br />
@@ -648,14 +654,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
648654
<sub><b>@rashiaggarwal06</b></sub>
649655
</a>
650656
</td>
657+
</tr>
658+
<tr>
651659
<td align="center" width="120">
652660
<a href="https://github.com/rishit537">
653661
<img src="https://github.com/rishit537.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="rishit537" /><br />
654662
<sub><b>@rishit537</b></sub>
655663
</a>
656664
</td>
657-
</tr>
658-
<tr>
659665
<td align="center" width="120">
660666
<a href="https://github.com/sakshicoded1111">
661667
<img src="https://github.com/sakshicoded1111.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="sakshicoded1111" /><br />
@@ -686,14 +692,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
686692
<sub><b>@shreyasgawande19</b></sub>
687693
</a>
688694
</td>
695+
</tr>
696+
<tr>
689697
<td align="center" width="120">
690698
<a href="https://github.com/siri-004">
691699
<img src="https://github.com/siri-004.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="siri-004" /><br />
692700
<sub><b>@siri-004</b></sub>
693701
</a>
694702
</td>
695-
</tr>
696-
<tr>
697703
<td align="center" width="120">
698704
<a href="https://github.com/snehacodes-2906">
699705
<img src="https://github.com/snehacodes-2906.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="snehacodes-2906" /><br />
@@ -724,14 +730,14 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
724730
<sub><b>@tanishkakora</b></sub>
725731
</a>
726732
</td>
733+
</tr>
734+
<tr>
727735
<td align="center" width="120">
728736
<a href="https://github.com/twinkle0tech">
729737
<img src="https://github.com/twinkle0tech.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="twinkle0tech" /><br />
730738
<sub><b>@twinkle0tech</b></sub>
731739
</a>
732740
</td>
733-
</tr>
734-
<tr>
735741
<td align="center" width="120">
736742
<a href="https://github.com/vedansht2211">
737743
<img src="https://github.com/vedansht2211.png?size=100" width="100" height="100" style="border-radius:50%; border:2px solid #555;" alt="vedansht2211" /><br />
@@ -762,7 +768,6 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
762768
<sub><b>@yuvraj-k-singh</b></sub>
763769
</a>
764770
</td>
765-
<td width="120"></td>
766771
</tr>
767772
</table>
768773
<!-- CONTRIBUTORS_END -->
Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
class Rock_Paper_Scissor:
1+
import random
2+
3+
class Rock_Paper_Scissors:
24
def __init__(self):
5+
"""Initializes the game state without blocking execution."""
36
self.user_score = 0
47
self.computer_score = 0
58
self.rounds_played = 0
6-
self.play_game()
9+
# Perfectly mirrors the JS choices array ['rock', 'paper', 'scissors']
10+
self.choices = ["rock", "paper", "scissors"]
711

812
def users_play(self):
9-
import random
10-
choices = ["rock", "paper", "scissor"]
11-
13+
"""Handles a single round of interaction."""
1214
user_choice = ""
13-
while user_choice not in choices:
14-
user_choice = input("Enter your choice (rock, paper, or scissor): ").lower()
15-
if user_choice not in choices:
16-
print("Invalid choice. Please choose rock, paper, or scissor.")
15+
while user_choice not in self.choices:
16+
user_choice = input("Enter your choice (rock, paper, or scissors): ").lower()
17+
if user_choice not in self.choices:
18+
print("Invalid choice. Please choose rock, paper, or scissors.")
1719

18-
computer_choice = random.choice(choices)
20+
computer_choice = random.choice(self.choices)
1921
print(f"Computer chose: {computer_choice}")
2022

2123
if user_choice == computer_choice:
22-
print("It's a Tie!")
24+
print("It's a Tie! 🤝")
2325
return "tie"
24-
elif (user_choice == "rock" and computer_choice == "scissor") or \
26+
elif (user_choice == "rock" and computer_choice == "scissors") or \
2527
(user_choice == "paper" and computer_choice == "rock") or \
26-
(user_choice == "scissor" and computer_choice == "paper"):
27-
print("You Win this round!")
28+
(user_choice == "scissors" and computer_choice == "paper"):
29+
print("You Win this round! 🎉")
2830
return "user"
2931
else:
30-
print("Computer Wins this round!")
32+
print("Computer Wins this round! 🤖")
3133
return "computer"
3234

33-
3435
def statistics(self):
36+
"""Displays performance statistics matching the web dashboard metrics."""
3537
print("\n--- Game Statistics ---")
3638
print(f"Rounds Played: {self.rounds_played}")
3739
print(f"Your Score: {self.user_score}")
3840
print(f"Computer Score: {self.computer_score}")
3941

40-
4142
def save_game(self):
43+
"""Appends the final game results to a local tracking log."""
4244
name = input("Enter your name to save the results (optional): ")
4345
if not name:
4446
name = "Anonymous"
@@ -50,27 +52,29 @@ def save_game(self):
5052
except IOError:
5153
print("Error: Could not save game results to file.")
5254

53-
5455
def play_game(self):
56+
"""Launches the primary interactive gameplay loop."""
5557
print("Welcome to Rock, Paper, Scissors!")
5658
while True:
5759
self.rounds_played += 1
5860
print(f"\n--- Round {self.rounds_played} ---")
5961

60-
round_winner = self.users_play() # Call the users_play method for one round
62+
round_winner = self.users_play()
6163

6264
if round_winner == "user":
6365
self.user_score += 1
6466
elif round_winner == "computer":
6567
self.computer_score += 1
6668

6769
self.statistics()
68-
play_again_input = input("do you want to play again ? (yes/no): ").lower()
70+
play_again_input = input("Do you want to play again? (yes/no): ").lower()
6971
if play_again_input != "yes":
7072
print("\nThanks for playing! Final results:")
7173
self.statistics()
7274
self.save_game()
7375
break
74-
75-
game = Rock_Paper_Scissor()
76-
print(game)
76+
77+
# Standard execution block ensuring clean instantiation
78+
if __name__ == "__main__":
79+
game = Rock_Paper_Scissors()
80+
game.play_game()

0 commit comments

Comments
 (0)