Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findAllSubs(word, let):
- out = []
- while word.find(let) + 1:
- p = word.find(let)
- out += [p]
- word = word[0:p] + "_" + word[p+1:]
- return out
- def get_placeholders(word):
- return " ".join([("_", l)["_" == word[i]] for i, l in enumerate(word)])
- def check_solved(word):
- return len(word.split("_")) == len(word) + 1
- def check(usedstr, let):
- if len(let) != 1:
- print("Нужно ввести букву!")
- return None
- if let in usedstr:
- print("Вы уже вводили эту букву!")
- return None
- return let
- def main():
- words = []
- usedstr = ""
- solved = False
- tries = 0
- word = "кошка"# random from 'words'
- bk = word[::]
- while 1 :
- if (tries >= 9 or check_solved(word)):
- break
- placeholders = get_placeholders(word)
- print(placeholders)
- a = None
- while not a:
- a = check(usedstr, input("Введите букву: ").lower())
- a = a.lower()
- k = findAllSubs(word, a)
- if len(k) == 0:
- print("Такой буквы нет! осталось попыток:", 9 - tries)
- tries += 1
- continue
- word = word.replace(a, "_")
- usedstr += a
- if tries == 9:
- print("Вы умерли! Слово было:", bk)
- else:
- print("GG, U WIN! Попыток:", tries)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement