Bingo mit Python, um die Zeit totzuschlagen. Ich hasse GUI, also benutze ich es nicht 5 * 5 Quadrate.
from random import choice
import itertools
import sys
def gett(dict, val):
return [k for k, v in dict.items() if v == val]
def op(list1, list2):
for x in list2:
hmm = len(x)
if len(set(x) & set(list1)) == hmm:
return True
return False
def bingo():
input("Please press the enter key.")
print("=========BINGO=========")
lis = list(range(1, 76))
def bingo_():
bingo_print = ""
for x in range(25):
c_c = choice(lis)
lis.remove(c_c)
if x % 5 == 4:
print(c_c)
bingo_print += str(c_c)+"\n"
elif x == 12:
print("× ", end="")
bingo_print += "× "
else:
if len(str(c_c)) == 1:
end_ = " "
else:
end_ = " "
print(c_c, end=end_)
bingo_print += str(c_c)+end_
ch = bingo_print.split("\n")
p = [x.split(" ") for x in ch]
for x in p:
for y in x:
if not y:
x.remove(y)
bind = dict(enumerate(list(itertools.chain.from_iterable(p))))
print("\033[A", end="")
print("=======================")
k = 0
xxx = list(range(1, 76))
while k < 40:
i = "×"
while i == "×":
i = choice(list(bind.values()))
for x in range(25000):
print("\r" + str(choice(xxx)), end="")
print("\r" + str(i))
if i in list(bind.values()):
print("\033[31mATARI!! OMEDETO!!\033[0m")
print("=========BINGO=========")
for x, y in enumerate(list(bind.values())):
if y == i:
bind[gett(bind, y)[0]] = "×"
y = "×"
x = int(x)
if x % 5 == 4:
print(y)
else:
if len(str(y)) == 1 or y == "×":
e = " "
else:
e = " "
print(y, end=e)
xyz = sorted(gett(bind, "×"))
zyx = [
list(range(4)),
list(range(5, 10)),
list(range(10, 15)),
list(range(15, 20)),
list(range(20, 25)),
[x*5 for x in range(5)],
[x*5+1 for x in range(5)],
[x*5+1 for x in range(5)],
[x*5+2 for x in range(5)],
[x*5+3 for x in range(5)],
[x*5+4 for x in range(5)],
[x*6 for x in range(5)],
[x*4 for x in range(4)]
]
global foo
foo = op(xyz, zyx)
print("======================")
else:
print("HAZURE!! MATAARUSA!!")
foo = False
k += 1
if k < 40:
i = input("Bist du ein Bingo geworden?\n(Y /N)")
if i.lower() == "y":
if foo:
print("Glückwunsch(・ З ・)")
sys.exit(0)
print("Lügner ┌(┌^o^)┐")
sys.exit(0)
elif i.lower() == "n":
if foo:
print("Lügner ┌(┌^o^)┐")
sys.exit(0)
else:
print("Iiko Iiko( ˊᵕˋ )")
else:
print("Unzulässige Zeichenfolge")
sys.exit(0)
bingo_()
bingo()
Es dauerte 3 Stunden. das war so schwer
Recommended Posts