М
Молодежь
К
Компьютеры-и-электроника
Д
Дом-и-сад
С
Стиль-и-уход-за-собой
П
Праздники-и-традиции
Т
Транспорт
П
Путешествия
С
Семейная-жизнь
Ф
Философия-и-религия
Б
Без категории
М
Мир-работы
Х
Хобби-и-рукоделие
И
Искусство-и-развлечения
В
Взаимоотношения
З
Здоровье
К
Кулинария-и-гостеприимство
Ф
Финансы-и-бизнес
П
Питомцы-и-животные
О
Образование
О
Образование-и-коммуникации
лол1628
лол1628
20.02.2022 00:22 •  Информатика

Ребят, хелп! Есть тут те кто разбирается в Python? В Приложении (Урок 4) приведен код игры «Крестики-
нолики». Создайте диалоговое окно, где пользователь
сможет выбрать тип игры: один игрок / два игрока.
Вот код
from tkinter import *
from tkinter import messagebox
from random import randint
from tkinter import simpledialog

ActivePlayer = 1
p1 = []
p2 = []
window = Tk()
window.title("Game")
button1 = Button(window, text = "")

name1 = simpledialog.askstring("Input", "Input Palyer 1 name", parent = window)
if name1 is not None:
print("Player 1 name", name1)
else:
print("No name")

name2 = simpledialog.askstring("Input", "Input Player 2 name", parent = window)
if name2 is not None:
print("Player 2 name", name2)
else:
print("No name")

button1.grid(row = 0, column = 0, sticky = "snew", ipadx = 40, ipady = 40)
button1.config(command = lambda: ButtonClick(1))
button2 = Button(window, text = "")
button2.grid(row = 0, column = 1, sticky = "snew", ipadx = 40, ipady = 40)
button2.config(command = lambda: ButtonClick(2))
button3 = Button(window, text = "")
button3.grid(row = 0, column = 2, sticky = "snew", ipadx = 40, ipady = 40)
button3.config(command = lambda: ButtonClick(3))
button4 = Button(window, text = "")
button4.grid(row = 1, column = 0, sticky = "snew", ipadx = 40, ipady = 40)
button4.config(command = lambda: ButtonClick(4))
button5 = Button(window, text = "")
button5.grid(row = 1, column = 1, sticky = "snew", ipadx = 40, ipady = 40)
button5.config(command = lambda: ButtonClick(5))
button6 = Button(window, text = "")
button6.grid(row = 1, column = 2, sticky = "snew", ipadx = 40, ipady = 40)
button6.config(command = lambda: ButtonClick(6))
button7 = Button(window, text = "")
button7.grid(row = 2, column = 0, sticky = "snew", ipadx = 40, ipady = 40)
button7.config(command = lambda: ButtonClick(7))
button8 = Button(window, text = "")
button8.grid(row = 2, column = 1, sticky = "snew", ipadx = 40, ipady = 40)
button8.config(command = lambda: ButtonClick(8))
button9 = Button(window, text = "")
button9.grid(row = 2, column = 2, sticky = "snew", ipadx = 40, ipady = 40)
button9.config(command = lambda: ButtonClick(9))

def ButtonClick(id):
global ActivePlayer
global p1
global p2
print("ID:{}".format(id))
if (ActivePlayer == 1):
SetLayout(id, "X")
p1.append(id)
ActivePlayer = 2
print("P1:{}".format(p1))
elif (ActivePlayer == 2):
SetLayout(id, "O")
p2.append(id)
ActivePlayer = 1
print("P2:{}".format(p2))
ChooseWinner()
def SetLayout(id, PlayerSymbol):
if (id == 1):
button1.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 2):
button2.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 3):
button3.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 4):
button4.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 5):
button5.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 6):
button6.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 7):
button7.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 8):
button8.config(text = PlayerSymbol,
state = DISABLED)
elif (id == 9):
button9.config(text = PlayerSymbol,
state = DISABLED)
def ChooseWinner():
Winner = -1
''' W I N N E R - 1 '''
if ((1 in p1) and (2 in p1) and (3 in p1)):
Winner = 1
if ((1 in p2) and (2 in p2) and (3 in p2)):
Winner = 2
if ((4 in p1) and (5 in p1) and (6 in p1)):
Winner = 1
if ((4 in p2) and (5 in p2) and (6 in p2)):
Winner = 2
if ((7 in p1) and (8 in p1) and (9 in p1)):
Winner = 1
if ((7 in p2) and (8 in p2) and (9 in p2)):
Winner = 2
''' W I N N E R - 2 '''
if ((1 in p1) and (4 in p1) and (7 in p1)):
Winner = 1
if ((1 in p2) and (4 in p2) and (7 in p2)):
Winner = 2
if ((2 in p1) and (6 in p1) and (8 in p1)):
Winner = 1
if ((2 in p2) and (6 in p2) and (8 in p2)):
Winner = 2
if ((3 in p1) and (7 in p1) and (9 in p1)):
Winner = 1
if ((3 in p2) and (7 in p2) and (9 in p2)):
Winner = 2
''' W I N N E R - 3 '''
if ((1 in p1) and (5 in p1) and (9 in p1)):
Winner = 1
if ((1 in p2) and (5 in p2) and (9 in p2)):
Winner = 2
if ((3 in p1) and (5 in p1) and (7 in p1)):
Winner = 1
if ((3 in p2) and (5 in p2) and (7 in p2)):
Winner = 2
if Winner == 1:
messagebox.showinfo("Winner", f"Player 1 {name1} is Winner")
elif Winner == 2:
messagebox.showinfo("Winner", f"Player 2 {name2} is Winner")
def AutoPlay():
global p1
global p2
EmplyCells = []
for i in range(9):
if ( (i+1 in p1) or (i+1 in p2)):
EmplyCells.append(i+1)
RandomIndex = randint(0, len(EmplyCells)-1)
ButtonClick(EmplyCells[RandomIndex])
window.mainloop()

👇
Ответ:
IUcenhik
IUcenhik
20.02.2022

Объяснение:

https://ru.stackoverflow.com/questions/900763/%D0%9A%D1%80%D0%B5%D1%81%D1%82%D0%B8%D0%BA%D0%B8-%D0%BD%D0%BE%D0%BB%D0%B8%D0%BA%D0%B8

Перейди по ссылке, тут подробно объяснено.

4,4(45 оценок)
Открыть все ответы
Ответ:
karinka20001202
karinka20001202
20.02.2022

program name;
var i,n,x,summa,count:integer;
nechet:boolean;
begin
Writeln('Vvedite n: ');
readln(n);//получаем n
summa:=0;
count:=0;
i:=1;
if(n mod 2 = 1) then nechet := true else nechet := false; //проверяем четное число или нет
while i<n do begin//пока число меньше n
if(nechet) then//если число нечентное
begin
summa:=summa+i*i*i;//прибавляем к сумме куб этого числа
end
else//если число четное
begin
summa:=summa+i*i;//прибавляем квадрат числа
end;
i:=i+1;//прибавляем число на 1
end;
writeln(' summa: ', summa);//выводим сумму
readln();
end.

4,6(91 оценок)
Ответ:
slavik528
slavik528
20.02.2022
25 (10cc) =2^4+2^3+2^0 =11001 (2cc)
19 (10cc)=2^4+2^1+2^0=10011 (2cc)

используя формулу А→В =¬А+В приводим данную формулу в условии к виду:
(X&25=0)+(X&19≠0) + (Х&A≠0)=1

рассмотрим случай, когда
(Х&25 =0) +(X&19≠0) =0   и  (Х&A≠0)=1

так как 25 = 11001, то (X&25=0) = 0   (т.е. конъюнкция будет "ложь")
при Х={1; 1000; 1001;  10000; 10001; 11000; 11001}

так как 19=10011, то (Х&19≠0) = 0 при
X={100; 1000;  1100}
                   общее значение : Х=1000 (2сс) = 8 (10сс)

ответ 8
4,5(50 оценок)
Это интересно:
Новые ответы от MOGZ: Информатика
logo
Вход Регистрация
Что ты хочешь узнать?
Спроси Mozg
Открыть лучший ответ