Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f2bd9d1

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 4242935 according to the output from Autopep8. Details: None
1 parent 27f24a8 commit f2bd9d1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎Grid Explorer/Grid_Explorer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import random
22

3+
34
def create_grid(size):
45
return [[' ' for _ in range(size)] for _ in range(size)]
56

7+
68
def place_treasure(grid, size):
79
row = random.randint(0, size - 1)
810
col = random.randint(0, size - 1)
911
grid[row][col] = 'T'
1012
return row, col
1113

14+
1215
def display_grid(grid):
1316
size = len(grid)
1417
for row in grid:
1518
print(' | '.join(cell.center(3) for cell in row))
1619
print('-' * (size * 5 - 1))
1720

21+
1822
def move_explorer(grid, row, col, direction):
1923
size = len(grid)
2024
if direction == 'up' and row > 0:
@@ -27,9 +31,11 @@ def move_explorer(grid, row, col, direction):
2731
col += 1
2832
return row, col
2933

34+
3035
def grid_explorer(size):
3136
grid = create_grid(size)
32-
explorer_row, explorer_col = random.randint(0, size - 1), random.randint(0, size - 1)
37+
explorer_row, explorer_col = random.randint(
38+
0, size - 1), random.randint(0, size - 1)
3339
treasure_row, treasure_col = place_treasure(grid, size)
3440

3541
print("Welcome to Grid Explorer!")
@@ -49,7 +55,8 @@ def grid_explorer(size):
4955
print("Invalid move. Try again.")
5056
continue
5157

52-
new_explorer_row, new_explorer_col = move_explorer(grid, explorer_row, explorer_col, move)
58+
new_explorer_row, new_explorer_col = move_explorer(
59+
grid, explorer_row, explorer_col, move)
5360

5461
if grid[new_explorer_row][new_explorer_col] == 'T':
5562
display_grid(grid)
@@ -60,5 +67,6 @@ def grid_explorer(size):
6067
explorer_row, explorer_col = new_explorer_row, new_explorer_col
6168
grid[explorer_row][explorer_col] = 'E'
6269

70+
6371
if __name__ == "__main__":
6472
grid_explorer(5)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /