# 6์ฅ Lab ๋์ ๋ฌธ์ ํ์ด
278p_Lab ๋์ ๋ฌธ์ )
def menu_choice(i):
if i == 1:
print(friends)
elif i == 2:
name = input('์ด๋ฆ์ ์
๋ ฅํ์์ค: ')
friends.append(name)
elif i == 3:
del_name = input('์ญ์ ํ ์ด๋ฆ์ ์
๋ ฅํ์์ค: ')
if del_name in friends:
friends.remove(del_name)
else:
print('์ด๋ฆ์ด ์น๊ตฌ ๋ชฉ๋ก์ ์กด์ฌํ์ง ์์ต๋๋ค.')
elif i == 4:
old_name = input('๋ณ๊ฒฝํ ์ด๋ฆ์ ์
๋ ฅํ์์ค: ')
if old_name in friends:
index = friends.index(old_name)
new_name = input('์ ์ด๋ฆ์ ์
๋ ฅํ์์ค: ')
friends[index] = new_name
else:
print('์ด๋ฆ์ด ์น๊ตฌ ๋ชฉ๋ก์ ์กด์ฌํ์ง ์์ต๋๋ค.')
menu = 0
friends = []
while menu != 5:
print('-------------------')
print('1. ์น๊ตฌ ๋ฆฌ์คํธ ์ถ๋ ฅ')
print('2. ์น๊ตฌ ์ถ๊ฐ')
print('3. ์น๊ตฌ ์ญ์ ')
print('4. ์ด๋ฆ ๋ณ๊ฒฝ')
print('5. ์ข
๋ฃ')
menu = int(input('๋ฉ๋ด๋ฅผ ์ ํํ์์ค: '))
menu_choice(menu)




287p_Lab ๋์ ๋ฌธ์ )
board = [[' ' for x in range (3)] for y in range(3)]
def print_board():
for r in range(3):
print(" " + board[r][0] + "| " + board[r][1] + "| " + board[r][2])
if (r != 2):
print("---|---|---")
def victory_check():
if board[0][0] != ' ' and board[1][1] == board[0][0] == board[2][2]:
return 10
elif board[0][2] != ' ' and board[0][2] == board[1][1] == board[2][0]:
return 10
elif board[0][0] != ' ' and board[0][0] == board[1][0] == board[2][0]:
return 10
elif board[0][1] != ' ' and board[0][1] == board[1][1] == board[2][1]:
return 10
elif board[0][2] != ' ' and board[0][2] == board[1][2] == board[2][2]:
return 10
elif board[0][0] != ' ' and board[0][0] == board[0][1] == board[0][2]:
return 10
elif board[1][0] != ' ' and board[1][0] == board[1][1] == board[1][2]:
return 10
elif board[2][0] != ' ' and board[2][0] == board[2][1] == board[2][2]:
return 10
else:
return 20
while True:
print_board()
# ์ฌ์ฉ์๋ก๋ถํฐ ์ขํ ์
๋ ฅ๋ฐ๊ธฐ
x = int(input("๋ค์ ์์ x์ขํ๋ฅผ ์
๋ ฅํ์์ค: "))
y = int(input("๋ค์ ์์ y์ขํ๋ฅผ ์
๋ ฅํ์์ค: "))
if board[x][y] != ' ':
print('์๋ชป๋ ์์น์
๋๋ค. ')
continue
else:
board[x][y] = 'X'
if victory_check() != 20:
print_board()
print('์ฌ์ฉ์ง ์น๋ฆฌ')
break
# ์ปดํจํฐ๊ฐ ๋๊ฐ์ ๋ฐฉํฅ์ ๋จผ์ ์ ์ ํ๋๋ก ์ฝ๋ ์ถ๊ฐ
done = False
for a in range(3):
if board[a][a] == ' ' and not done:
board[a][a] = 'O'
done = True
break
# ๋ง์ฝ ๋๊ฐ์ ๊ณต๊ฐ์ด ๋ค ์ฐจ๊ณ ์์ผ๋ฉด ์ฒซ ๋ฒ์งธ๋ก ๋ฐ๊ฒฌํ๋ ๊ณต๋ ์ ํ
if done == False:
for i in range(3):
for j in range(3):
if board[i][j] == ' ' and not done:
board[i][j] = 'O'
done = True
break
if victory_check() != 20:
print_board()
print('์ปดํจํฐ ์น๋ฆฌ')
break



289p_Lab ๋์ ๋ฌธ์ )
import random
Computer_Board = []
User_Board = []
for computer in range(10):
Computer_Board.append(['.'] * 10)
for user in range(11):
User_Board.append(['.'] * 10)
def main():
global User_Board
global Computer_Board
print_Board(User_Board)
user_input = input('ํ๊ณผ ์ด์ ์
๋ ฅํ์์ค: ')
x, y = user_input.split(",")
x, y = int(x), int(y)
generate_Board(x, y)
open_tile(x, y)
while True:
print_Board(User_Board)
user_input = input('ํ๊ณผ ์ด์ ์
๋ ฅํ์์ค: ')
x, y = user_input.split(",")
x, y = int(x), int(y)
open_tile(x, y)
if check_victory() == 1:
exit()
def generate_Board(x, y):
global Computer_Board
global User_Board
for row in range(10):
for col in range(10):
if random.random() < 0.3:
Computer_Board[row][col] = '#'
for row in range(y - 2, y + 1):
for col in range(x - 2, x + 1):
Computer_Board[row][col] = '.'
for row in range(10):
for col in range(10):
Mine_Num = 0
if Computer_Board[row][col] == '.':
if 0 <= (row - 1) and (row - 1) <= 9 and 0 <= (col - 1) and (col - 1) <= 9:
if Computer_Board[row - 1][col - 1] == '#':
Mine_Num += 1
if 0 <= (row - 1) and (row - 1) <= 9 and 0 <= (col) and (col) <= 9:
if Computer_Board[row - 1][col] == '#':
Mine_Num += 1
if 0 <= (row - 1) and (row - 1) <= 9 and 0 <= (col + 1) and (col + 1) <= 9:
if Computer_Board[row - 1][col + 1] == '#':
Mine_Num += 1
if 0 <= (row) and (row) <= 9 and 0 <= (col - 1) and (col - 1) <= 9:
if Computer_Board[row][col - 1] == '#':
Mine_Num += 1
if 0 <= (row) and (row) <= 9 and 0 <= (col + 1) and (col + 1) <= 9:
if Computer_Board[row][col + 1] == '#':
Mine_Num += 1
if 0 <= (row + 1) and (row + 1) <= 9 and 0 <= (col - 1) and (col - 1) <= 9:
if Computer_Board[row + 1][col - 1] == '#':
Mine_Num += 1
if 0 <= (row + 1) and (row + 1) <= 9 and 0 <= (col) and (col) <= 9:
if Computer_Board[row + 1][col] == '#':
Mine_Num += 1
if 0 <= (row + 1) and (row + 1) <= 9 and 0 <= (col + 1) and (col + 1) <= 9:
if Computer_Board[row + 1][col + 1] == '#':
Mine_Num += 1
Computer_Board[row][col] = str(Mine_Num)
def print_Board(board):
for row in range(10):
for col in range(10):
print(board[row][col], end=' ')
print('')
def open_tile(x, y):
global User_Board
global Computer_Board
if Computer_Board[y - 1][x - 1] == '#':
User_Board[y - 1][x - 1] = Computer_Board[y - 1][x - 1]
print_Board(User_Board)
print('Game over!')
exit()
else:
Continue_Open(x, y)
def Continue_Open(x, y):
global User_Board
global Computer_Board
User_Board[y - 1][x - 1] = Computer_Board[y - 1][x - 1]
row = x - 1
col = y - 1
if Computer_Board[col][row] == '0':
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
if Computer_Board[col - 1][row - 1] == '0' and User_Board[col - 1][row - 1] == '.':
Continue_Open(x - 1, y - 1)
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row) and (row) <= 9:
if Computer_Board[col - 1][row] == '0' and User_Board[col - 1][row] == '.':
Continue_Open(x, y - 1)
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
if Computer_Board[col - 1][row + 1] == '0' and User_Board[col - 1][row + 1] == '.':
Continue_Open(x + 1, y - 1)
if 0 <= (col) and (col) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
if Computer_Board[col][row - 1] == '0' and User_Board[col][row - 1] == '.':
Continue_Open(x - 1, y)
if 0 <= (col) and (col) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
if Computer_Board[col][row + 1] == '0' and User_Board[col][row + 1] == '.':
Continue_Open(x + 1, y)
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
if Computer_Board[col + 1][row - 1] == '0' and User_Board[col + 1][row - 1] == '.':
Continue_Open(x - 1, y + 1)
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row) and (row) <= 9:
if Computer_Board[col + 1][row] == '0' and User_Board[col + 1][row] == '.':
Continue_Open(x, y + 1)
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
if Computer_Board[col + 1][row + 1] == '0' and User_Board[col + 1][row + 1] == '.':
Continue_Open(x + 1, y + 1)
if Computer_Board[col][row] == '0':
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
User_Board[col - 1][row - 1] = Computer_Board[col - 1][row - 1]
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row) and (row) <= 9:
User_Board[col - 1][row] = Computer_Board[col - 1][row]
if 0 <= (col - 1) and (col - 1) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
User_Board[col - 1][row + 1] = Computer_Board[col - 1][row + 1]
if 0 <= (col) and (col) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
User_Board[col][row - 1] = Computer_Board[col][row - 1]
if 0 <= (col) and (col) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
User_Board[col][row + 1] = Computer_Board[col][row + 1]
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row - 1) and (row - 1) <= 9:
User_Board[col + 1][row - 1] = Computer_Board[col + 1][row - 1]
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row) and (row) <= 9:
User_Board[col + 1][row] = Computer_Board[col + 1][row]
if 0 <= (col + 1) and (col + 1) <= 9 and 0 <= (row + 1) and (row + 1) <= 9:
User_Board[col + 1][row + 1] = Computer_Board[col + 1][row + 1]
def check_victory():
global User_Board
exit_game = 0
for row in range(10):
for col in range(10):
if Computer_Board[row][col] != '#':
if User_Board[row][col] == Computer_Board[row][col]:
exit_game = 1
else:
exit_game = 0
return 0
if exit_game == 1:
print('Victory!')
return 1
main()






