Projects_from_the_book/main.py

66 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import random
max_nam = 10
guess_num = 3
def create_secret_num(guess_num):
digits = list('0123456789')
random.shuffle(digits)
return ''.join(digits[:guess_num])
def attempt_check(attemt, secret_num):
clue = []
for i in range(len(attemt)):
if attemt[i] == secret_num[i]:
clue.append("Fermi")
elif attemt[i] in secret_num:
clue.append("Pico")
sorted(clue)
return ' '.join(clue) if clue else 'Bagels'
def game(max_nam, guess_num):
print("I meade a number.")
attemt_num = 1
level = 1
while True:
if max_nam <= attemt_num:
break
if level != 1:
max_nam += 2
guess_num += 1
attemt_num = 1
secret_num = create_secret_num(guess_num)
while max_nam >= attemt_num:
attemt = ''
print(f"You have {max_nam} attempt and {guess_num}-digit number")
while len(attemt) != guess_num or not attemt.isdecimal():
print(f"Attemt {attemt_num}, Level {level}") # Вывод информации о том, сколько попыток сделал игрок
attemt = input("> ")
if secret_num == attemt:
print("You win!")
print("Next level...")
break
print(attempt_check(attemt,secret_num)) # А вот и подсказка
attemt_num += 1
level += 1
print("You're done trying")
print(f"The hiden numbers is {secret_num}")
def main():
while True:
game(max_nam, guess_num)
if input("You want repeat the game?> ").lower().startswith('n'):
print("Thanks for playing")
break
if __name__ == '__main__':
main()