1. Генератор Mad Libs


with open("youtube_alarm_videos.txt", "r") as



Yüklə 42,3 Kb.
səhifə8/9
tarix09.09.2023
ölçüsü42,3 Kb.
#142167
növüПрограмма
1   2   3   4   5   6   7   8   9
python primeri1

with open("youtube_alarm_videos.txt", "r") as alarm_file:

videos = alarm_file.readlines()

# Open a random video from the list

webbrowser.open(random.choice(videos))


8. Tic-Tac-Toe 
Tic-Tac-Toe is a two-player game that involves a nine-square grid. Each player marks their space with an O or an X alternately. The player who manages to mark three Os or Xs diagonally, horizontally, or vertically wins. Each player must block their opponent while attempting to make their chain. For this project, we use the Pygame Python library
Sample Code: 
""" Tic Tac Toe

----------------------------------------

"""

import random

import sys

board=[i for i in range(0,9)]

player, computer = '',''

# Corners, Center and Others, respectively

moves=((1,7,3,9),(5,),(2,4,6,8))

# Winner combinations

winners=((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6))

# Table


tab=range(1,10)

def print_board():

x=1


for i in board:

end = ' | '



if x%3 == 0:

end = ' \n'



if i != 1: end+='---------\n';

char=' '


if i in ('X','O'): char=i;

x+=1


print(char,end=end)

def select_char():

chars=('X','O')



if random.randint(0,1) == 0:

return chars[::-1]

return chars

def can_move(brd, player, move):

if move in tab and brd[move-1] == move-1:

return True

return False

def can_win(brd, player, move):

places=[]

x=0

for i in brd:

if i == player: places.append(x);

x+=1


win=True


Yüklə 42,3 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin