You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: projects/Battleship/main.py
+25-17Lines changed: 25 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,21 @@
7
7
8
8
defnew_game():
9
9
globalsize
10
-
os.system('cls'ifos.name=='nt'else'clear')
10
+
os.system("cls"ifos.name=="nt"else"clear")
11
11
answer=input("Do you want to start a new game of Battleship? ").lower()
12
12
13
-
ifanswernotin ['yes', 'y', 'no', 'n']:
13
+
ifanswernotin ["yes", "y", "no", "n"]:
14
14
new_game()
15
15
else:
16
-
ifanswer=='yes'oranswer=='y':
16
+
ifanswer=="yes"oranswer=="y":
17
17
whileTrue:
18
18
try:
19
-
os.system('cls'ifos.name=='nt'else'clear')
20
-
size=int(input(
21
-
"Enter a number between 5 and 15.\n\nThis will determine how big the playing board is and how many turns you have to find the Battleship. (5 rows, 5 columns, 5 turns, etc.): "))
19
+
os.system("cls"ifos.name=="nt"else"clear")
20
+
size=int(
21
+
input(
22
+
"Enter a number between 5 and 15.\n\nThis will determine how big the playing board is and how many turns you have to find the Battleship. (5 rows, 5 columns, 5 turns, etc.): "
23
+
)
24
+
)
22
25
ifsizenotinrange(5, 16):
23
26
raiseValueError()
24
27
exceptValueError:
@@ -31,11 +34,11 @@ def new_game():
31
34
forxinrange(0, size):
32
35
board.append(["O"] *size)
33
36
game()
34
-
elifanswer=='no'oranswer=='n':
35
-
os.system('cls'ifos.name=='nt'else'clear')
37
+
elifanswer=="no"oranswer=="n":
38
+
os.system("cls"ifos.name=="nt"else"clear")
36
39
print("Thank you for playing!\n")
37
40
input("Press the 'Enter' key to exit the game.")
38
-
os.system('cls'ifos.name=='nt'else'clear')
41
+
os.system("cls"ifos.name=="nt"else"clear")
39
42
quit()
40
43
41
44
@@ -54,10 +57,11 @@ def random_col(board):
54
57
55
58
defgame():
56
59
globalboard
57
-
os.system('cls'ifos.name=='nt'else'clear')
60
+
os.system("cls"ifos.name=="nt"else"clear")
58
61
print(
59
-
"Welcome to Battleship.\n\nA ship, one cell long, has been randomly placed on the below %dx%d grid.\nYou have %d turns to find it.\n"% (
60
-
size, size, size))
62
+
"Welcome to Battleship.\n\nA ship, one cell long, has been randomly placed on the below %dx%d grid.\nYou have %d turns to find it.\n"
63
+
% (size, size, size)
64
+
)
61
65
62
66
# Randomly places Battleship
63
67
ship_row=random_row(board)
@@ -98,21 +102,25 @@ def game():
98
102
99
103
# Checks if Player wins
100
104
ifguess_row==ship_rowandguess_col==ship_col:
101
-
os.system('cls'ifos.name=='nt'else'clear')
102
-
input("Congratulations! You sank my battleship!\n\nPress enter to continue.")
105
+
os.system("cls"ifos.name=="nt"else"clear")
106
+
input(
107
+
"Congratulations! You sank my battleship!\n\nPress enter to continue."
108
+
)
103
109
board= []
104
110
new_game()
105
111
break
106
112
else: # Guesses are outside of playing field
107
-
if (guess_row>sizeorguess_row<0) or (guess_col>sizeorguess_col<0):
113
+
if (guess_row>sizeorguess_row<0) or (
114
+
guess_col>sizeorguess_col<0
115
+
):
108
116
print("Oops, that's not even in the ocean.")
109
117
# Player previously guessed their current guesses
110
118
elifboard[guess_row][guess_col] =="X":
111
-
os.system('cls'ifos.name=='nt'else'clear')
119
+
os.system("cls"ifos.name=="nt"else"clear")
112
120
print("You guessed that one already. Good job, you wasted a turn.\n")
This project is designed to extract large datasets of book information from Goodreads based on user ratings. It includes a Python script, main.py, which scrapes book data from Goodreads pages and saves it to an Excel file.
2
+
3
+
Provide Input:
4
+
Enter the exact link to the book list on the Goodreads website.
5
+
Specify the minimum rating threshold for the books you want to extract.
6
+
Input the total number of web pages in your book list.
7
+
8
+
Data Extraction:
9
+
The script will start extracting book data based on the specified criteria.
10
+
It will create an Excel file named books.xlsx in the project directory.
11
+
The extracted book information will be saved in this file.
12
+
Excel File:
13
+
14
+
You can find the extracted book data in the books.xlsx file in the project folder.
This is a Python program used to simulate a coin toss, in which a user is asked to pick a side (heads or tails), and the program selects a result at random between the two options. If the user's choice matches the result, they win the coin toss.
4
+
5
+
### How to Play
6
+
7
+
1. When the program is initiated, you will be prompted to choose either "heads" or "tails".
8
+
2. The program will then determine the winning result by random chance, and display it.
9
+
3. If your choice matches the result, you win the coin toss. If not, you'll receive a "OOF" message to indicate a loss.
10
+
4. After the end of each round, you will be asked if you want to play again. Type "yes" to continue playing or "no" to exit the program.
0 commit comments