Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def passcode():
- if passcode.counter != 0:
- return passcode.code
- length = random.randint(1, 6)
- code = []
- while len(code) < length:
- digit = random.randint(0, 9)
- if digit not in code:
- code.append(digit)
- passcode.counter += 1
- passcode.code = code
- return passcode.code
- def int_out(t1):
- l1 = [int(a) for a in list(t1)]
- trafienia = 0
- dopasowania = 0
- if int_checker(l1) == 0:
- return "cyfra się powtarza"
- if int_checker(l1) == 1:
- return "odpowiedź za długa (>6 cyfr)"
- for a in l1:
- if a in passcode():
- if l1.index(a) == passcode().index(a):
- trafienia += 1
- hint2_mem(a, passcode().index(a))
- else:
- dopasowania += 1
- if trafienia == len(passcode()):
- wyn.score += 1
- return "win"
- else:
- wyn.score += 1
- return "trafienia: " + str(trafienia) + "\n" + "dopasowania: " + str(dopasowania)
- def int_checker(l1):
- if len(set(l1)) != len(l1):
- return 0
- elif len(set(l1)) > 6:
- return 1
- else:
- return 2
- def str_out(t1):
- if t1 == "w":
- return "aktualny wynik: " + str(wyn.score)
- elif t1 == "h":
- if str_out.counter == 0:
- str_out.counter += 1
- return hint1()
- elif str_out.counter == 1:
- str_out.counter += 1
- return hint2()
- else:
- return hint3()
- else:
- return "nieznana komenda"
- def hint1():
- return "długość hasła: " + str(len(passcode()))
- def hint2_mem(num, ind):
- hint2_mem.out[ind] = num
- def hint2():
- t1 = ""
- for a in hint2_mem.out:
- t1 += str(a)
- return "hasło: " + t1
- def hint3():
- prompt1 = str(input("czy chcesz powtórzyć podpowiedź? (t/n) "))
- if prompt1 == "t":
- prompt2 = input("którą? (1/2) ")
- if prompt2 == "1":
- wyn.score += 1
- return hint1()
- elif prompt2 == "2":
- wyn.score += 5
- return hint2()
- else:
- return "nieznana komenda"
- elif prompt1 == "n":
- return "\r"
- else:
- return "nieznana komenda"
- def inp():
- t1 = input(":")
- if inp_type(t1) == 1:
- return int_out(t1)
- else:
- return str_out(t1)
- def inp_type(t1):
- try:
- int(t1)
- return 1
- except:
- return 0
- def wyn(x):
- wyn.score += x
- passcode.counter = 0
- str_out.counter = 0
- wyn.score = 0
- hint2_mem.out = ["*" for _ in passcode()]
- print("Istrukcja:\n\nCelem gry jest odgadnięcie wygenerowanego hasła (1-6 różnych cyfr), z jak najniższym wynikiem\n\nGra polega na wpisywaniu porpozycji, a program odpowie, ile cyfr z propozycji znajduje się na poprawnej pozycji (trafienia), a ile gdzieś indziej w haśle (dopasowania).\n\nkomendy:\nw - podaje aktualny wynik\nh - daje podpowiedź\n po raz pierwszy podaje długość hasła\n po raz drugi podaje aktualnie znalezione cyfry\n po raz kolejny można powtórzyć podpowiedź 1 lub 2 kosztem odpowiednio 1 i 5 punktów")
- while True:
- ot = inp()
- print(ot)
- if ot == "win":
- break
- print("wynik: " + str(wyn.score))
Advertisement
Add Comment
Please, Sign In to add comment