Skip to content

Commit 2a263fd

Browse files
authored
Merge branch 'avinashkranjan:master' into anime-multiple-spaces-bug
2 parents 56240cd + bd5b280 commit 2a263fd

File tree

259 files changed

+97627
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+97627
-201
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
The provided code is a Python script that utilizes the `webbrowser` module to open a specified website multiple times in separate browser tabs.
2+
3+
Here is a description and documentation for the code:
4+
5+
1. The `webbrowser` module is imported at the beginning of the code. This module provides a high-level interface to allow displaying web-based documents to users.
6+
7+
The webbrowser module is a standard library module in Python, which means it is already included with your Python installation. You don't need to install it separately. It should be available and ready to use without any additional steps.
8+
9+
2. The user is prompted to enter the number of times they want to open the website. The input is stored in the variable `n` as an integer.
10+
11+
3. A `for` loop is used to iterate `n` times. The loop variable `e` represents the current iteration.
12+
13+
4. Inside the loop, the `webbrowser.open_new_tab()` function is called, passing the URL of the website to open as an argument. This function opens the URL in a new browser tab.
14+
15+
5. After the loop completes all iterations, the script execution ends.
16+
17+
Note: It's worth mentioning that the `webbrowser` module's behavior may vary depending on the operating system and the default web browser settings. Additionally, some web browsers may restrict or block the automatic opening of multiple tabs for security reasons.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import webbrowser # Import the webbrowser module
2+
3+
n = int(input('enter how many times you want to open website?')) # Prompt user for the number of times to open the website
4+
5+
for e in range(n): # Loop 'n' times
6+
webbrowser.open_new_tab('https://github.com/avinashkranjan/Amazing-Python-Scripts') # Open the specified website in a new tab

AI TicTacToe/src/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# TicTacToe Game
2+
3+
A simple implementation of the Tic Tac Toe game in Python.
4+
5+
## Rules of the Game
6+
Tic Tac Toe is a classic game played on a 3x3 grid. Two players take turns placing their markers (X or O) on the board, aiming to get three of their marks in a row (horizontally, vertically, or diagonally) before the opponent does. If all the positions on the board are filled and no player has won, the game ends in a tie.
7+
8+
## How to Play
9+
1. Run the `play_tic_tac_toe()` function in a Python environment.
10+
2. Player 1 will be prompted to choose either X or O.
11+
3. The players will take turns entering their positions on the board, ranging from 1 to 9. The board is displayed after each move.
12+
4. The game continues until one player wins or the board is full.
13+
5. After the game ends, players are given the option to play again.
14+
15+
## Functions
16+
- `display_board(board)`: Prints the current state of the Tic Tac Toe board.
17+
- `player_input()`: Prompts the first player to choose X or O and assigns the markers to player 1 and player 2 accordingly.
18+
- `place_marker(board, marker, position)`: Places the given marker (X or O) at the specified position on the board.
19+
- `win_check(board, mark)`: Checks if the given mark (X or O) has won the game.
20+
- `choose_first()`: Randomly selects which player goes first.
21+
- `space_check(board, position)`: Checks if a particular position on the board is empty.
22+
- `full_board_check(board)`: Checks if the board is full.
23+
- `player_choice(board)`: Asks the current player to choose a position to place their marker and returns the chosen position.
24+
- `replay()`: Asks the players if they want to play again.
25+
26+
## Usage
27+
1. Clone the repository or download the `tic_tac_toe.py` file.
28+
2. Open the file in a Python environment (e.g., IDLE, Jupyter Notebook, or any text editor with Python support).
29+
3. Run the script to start the game.
30+
4. Follow the prompts and enter your choices accordingly.
31+
5. Enjoy playing Tic Tac Toe!

AI TicTacToe/src/TicTacToe.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import random
2+
3+
def display_board(board):
4+
print('-------------')
5+
print('| ' + board[7] + ' | ' + board[8] + ' | ' + board[9] + ' |')
6+
print('-------------')
7+
print('| ' + board[4] + ' | ' + board[5] + ' | ' + board[6] + ' |')
8+
print('-------------')
9+
print('| ' + board[1] + ' | ' + board[2] + ' | ' + board[3] + ' |')
10+
print('-------------')
11+
12+
13+
def player_input():
14+
marker = ''
15+
while marker != 'X' and marker != 'O':
16+
marker = input('Player 1, choose X or O: ').upper()
17+
player1 = marker
18+
player2 = 'O' if player1 == 'X' else 'X'
19+
return player1, player2
20+
21+
22+
def place_marker(board, marker, position):
23+
board[position] = marker
24+
25+
26+
def win_check(board, mark):
27+
winning_combinations = [
28+
[1, 2, 3], [4, 5, 6], [7, 8, 9], # rows
29+
[1, 4, 7], [2, 5, 8], [3, 6, 9], # columns
30+
[1, 5, 9], [3, 5, 7] # diagonals
31+
]
32+
return any(all(board[i] == mark for i in combination) for combination in winning_combinations)
33+
34+
35+
def choose_first():
36+
return random.choice(['Player 1', 'Player 2'])
37+
38+
39+
def space_check(board, position):
40+
return board[position] == ' '
41+
42+
43+
def full_board_check(board):
44+
return all(board[i] != ' ' for i in range(1, 10))
45+
46+
47+
def player_choice(board):
48+
position = 0
49+
while position not in range(1, 10) or not space_check(board, position):
50+
position = int(input('Choose a position (1-9): '))
51+
return position
52+
53+
54+
def replay():
55+
choice = input('Do you want to play again? Enter Yes or No: ')
56+
return choice.lower() == 'yes'
57+
58+
59+
def play_tic_tac_toe():
60+
print('Welcome to Tic Tac Toe!')
61+
while True:
62+
the_board = [' '] * 10
63+
player1_marker, player2_marker = player_input()
64+
turn = choose_first()
65+
print(turn + ' will go first.')
66+
play_game = input('Are you ready to play? Enter y or n: ')
67+
if play_game.lower() == 'y':
68+
game_on = True
69+
else:
70+
game_on = False
71+
72+
while game_on:
73+
if turn == 'Player 1':
74+
display_board(the_board)
75+
position = player_choice(the_board)
76+
place_marker(the_board, player1_marker, position)
77+
78+
if win_check(the_board, player1_marker):
79+
display_board(the_board)
80+
print('Player 1 has won!')
81+
game_on = False
82+
else:
83+
if full_board_check(the_board):
84+
display_board(the_board)
85+
print('TIE GAME!')
86+
game_on = False
87+
else:
88+
turn = 'Player 2'
89+
else:
90+
display_board(the_board)
91+
position = player_choice(the_board)
92+
place_marker(the_board, player2_marker, position)
93+
94+
if win_check(the_board, player2_marker):
95+
display_board(the_board)
96+
print('Player 2 has won!')
97+
game_on = False
98+
else:
99+
if full_board_check(the_board):
100+
display_board(the_board)
101+
print('TIE GAME!')
102+
game_on = False
103+
else:
104+
turn = 'Player 1'
105+
106+
if not replay():
107+
if play_game.lower() == 'n':
108+
print('BYE! Have a good day.')
109+
else:
110+
print('Thank you for playing.')
111+
break
112+
113+
# Start the game
114+
play_tic_tac_toe()

Age-Calculator-GUI/age_calc_gui.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def check_year():
5353
try:
5454
year = int(self.yearEntry.get())
5555
if today.year - year < 0:
56-
self.statement = tk.Label(text=f"{nameValue.get()}'s age cannot be negative.", font="courier 10", bg="lightblue")
56+
self.statement = tk.Label(text=f"{nameValue.get()}'s age\n cannot be negative.", font="courier 10", bg="lightblue")
5757
self.statement.grid(row=6, column=1, pady=15)
5858
return False
5959
else:
6060
return True
6161
except Exception as e:
62-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth year cannot parse to int.", font="courier 10", bg="lightblue")
62+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth year\n cannot parse to int.", font="courier 10", bg="lightblue")
6363
self.statement.grid(row=6, column=1, pady=15)
6464
return False
6565

@@ -69,13 +69,13 @@ def check_month():
6969
try:
7070
month = int(self.monthEntry.get())
7171
if month < 0 or month > 12:
72-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month is outside 1-12.", font="courier 10", bg="lightblue")
72+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n is outside 1-12.", font="courier 10", bg="lightblue")
7373
self.statement.grid(row=6, column=1, pady=15)
7474
return False
7575
else:
7676
return True
7777
except Exception as e:
78-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month cannot parse to int.", font="courier 10", bg="lightblue")
78+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n cannot parse to int.", font="courier 10", bg="lightblue")
7979
self.statement.grid(row=6, column=1, pady=15)
8080
return False
8181

@@ -85,13 +85,13 @@ def check_day():
8585
try:
8686
day = int(self.dayEntry.get())
8787
if day < 0 or day > 31:
88-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth day is outside 1-31.", font="courier 10", bg="lightblue")
88+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth day is\n outside 1-31.", font="courier 10", bg="lightblue")
8989
self.statement.grid(row=6, column=1, pady=15)
9090
return False
9191
else:
9292
return True
9393
except Exception as e:
94-
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month cannot parse to int.", font="courier 10", bg="lightblue")
94+
self.statement = tk.Label(text=f"{nameValue.get()}'s birth month\n cannot parse to int.", font="courier 10", bg="lightblue")
9595
self.statement.grid(row=6, column=1, pady=15)
9696
return False
9797

Age_Calculator/Age_Calculator.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# importing the date module from the datetime package
2+
from datetime import date
3+
4+
# defining a function calculate the age
5+
def calculate_age(birthday):
6+
7+
# using the today() to retrieve today's date and stored it in a variable
8+
today = date.today()
9+
10+
# a bool representing if today's day, or month precedes the birth day, or month
11+
day_check = ((today.month, today.day) < (birthday.month, birthday.day))
12+
13+
# calculating the difference between the current year and birth year
14+
year_diff = today.year - birthday.year
15+
16+
# The difference in years is not enough.
17+
# We must subtract 0 or 1 based on if today precedes the
18+
# birthday's month/day from the year difference to get it correct.
19+
# we will subtract the 'day_check' boolean from 'year_diff'.
20+
# The boolean value will be converted from True to 1 and False to 0 under the hood.
21+
age_in_years = year_diff - day_check
22+
23+
# calculating the remaining months
24+
remaining_months = abs(today.month - birthday.month)
25+
26+
# calculating the remaining days
27+
remaining_days = abs(today.day - birthday.day)
28+
29+
# printing the age for the users
30+
print("Age:", age_in_years, "Years", remaining_months, "Months and", remaining_days, "days")
31+
32+
# main function
33+
if __name__ == "__main__":
34+
35+
# printing an opening statement
36+
print("Simple Age Calculator")
37+
38+
# asking user to enter birth year, birth month, and birth date
39+
birthYear = int(input("Enter the birth year: "))
40+
birthMonth = int(input("Enter the birth month: "))
41+
birthDay = int(input("Enter the birth day: "))
42+
43+
# converting integer values to date format using the date() method
44+
dateOfBirth = date(birthYear, birthMonth, birthDay)
45+
46+
# calling the function to calculate the age of a person
47+
calculate_age(dateOfBirth)

Age_Calculator/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
**Age_Calculator**
2+
3+
4+
5+
**Step1:**
6+
7+
First of all, we need to import two libraries into our code. The first one is the time and date
8+
9+
**Step2:**
10+
11+
Now, just use Age_Calculator.py code run it on online r any complier
12+
13+
**Step3:**
14+
15+
It will frist your date of birth year!
16+
17+
**Step4:**
18+
19+
Then it will ask your birth month!
20+
21+
**Step5:**
22+
23+
Then it will ask your birth day!
24+
25+
**Step6:**
26+
27+
Finally it will just a date of you enterted and current date and time it will print the the years and months days!
28+
29+
**conclusion:**
30+
31+
It is useful to Calculate birthdays in years!

Amazon-Price-Tracker/README.MD

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center"> Amazon Price Tracker</h1>
2-
Tracks the current given product price.
2+
Tracks the current given product price and provides alerts on price drop on email and whatsapp.
33

44
---------------------------------------------------------------------
55

@@ -8,15 +8,16 @@ Tracks the current given product price.
88
- bs4 (BeautifuSoup)
99
- time
1010
- smtplib
11+
- pywhatkit
12+
- datetime
1113

12-
[requirements.txt]()
14+
[requirements.txt](Amazon-Price-Tracker/requirements.txt)
1315
<hr>
1416

1517
## How it works
1618
- By providing the User agent name and URL of the product that you want to track and buy and then it scrap the web and it
1719
tracks your product price.
18-
19-
- It returns The Tracking price of your product and it sends email when your product price decreases
20+
- It returns The Tracking price of your product and it sends email and whatsapp message when your product price decreases
2021
at best least price.
2122

22-
#### By [Avinash Kr. Ranjan](https://github.com/avinashkranjan)
23+
#### By [Avinash Kr. Ranjan](https://github.com/avinashkranjan)

0 commit comments

Comments
 (0)