Adding functions, notes, conditions

This commit is contained in:
User 2025-05-01 12:44:17 +03:00
parent 2b90bb8f3a
commit 90ed40714f
1 changed files with 48 additions and 22 deletions

70
main.py
View File

@ -3,46 +3,72 @@ import random
max_nam = 10 max_nam = 10
guess_num = 3 guess_num = 3
digits = "0123456789"
while True:
digits = list(digits) def create_secret_num():
"""Создание случайного числа"""
digits = list('0123456789')
random.shuffle(digits) random.shuffle(digits)
secret_num = '' secret_num = ''
for i in digits[0:3]: for i in digits[0:3]:
secret_num += i secret_num += i
print(secret_num)
return secret_num
print("I mean digit.") def attempt_check():
attemt_num = 1 clue = []
for i in range(len(attemt)):
if secret_num[i] == attemt[i]:
clue.append("Fermi")
if attemt[i] in secret_num:
clue.append("Pico")
return ''.join(clue)
while True:
"""Основной цикл для прекращения или повторения игры"""
secret_num = create_secret_num() # Создание случайного числа
print("I meade a number.") # По сути, не нужное оповещение о создание числа(Создано для игрока)
attemt_num = 1 # Номер попытки игрока
while max_nam >= attemt_num: while max_nam >= attemt_num:
attemt = '' """Цикл, за счет которого осуществляются попытки"""
attemt = '' # Попытка игрока
while len(attemt) != guess_num or not attemt.isdecimal(): while len(attemt) != guess_num or not attemt.isdecimal():
print(f"Attemt № {attemt_num}") """Цикл для ввода попытки. Его можно было бы реализовать через if-elif,
но тогда у игрока была бы одна попытка."""
print(f"Attemt № {attemt_num}") # Вывод информации о том, сколько попыток сделал игрок
attemt = input("> ") attemt = input("> ")
clue = [] """Часть игры, где происходит проверка введенного игроком числа с загаданным(секретным) числом"""
if secret_num == attemt: if secret_num == attemt:
"""Проверка, полностью ли совпало число.
Её нельзя впихнуть в функцию attempt_check(), так как здесь есть ""break"""
print("You win!") print("You win!")
break break
for i in range(len(attemt)): clue = attempt_check() # А вот и подсказка
if secret_num[i] == attemt[i]:
clue.append("Fermi")
if attemt[i] in secret_num:
clue.append("Pico")
if len(clue) == 0: if len(clue) == 0:
print("Bagle") print("Bagle")
else: else:
sorted(clue) print(clue)
print(' '.join(clue))
attemt_num += 1 attemt_num += 1
print("You spent your attemt")
print(f"You want repit the game. The hiden numbers is {secret_num}? 'yes' or 'no'") if max_nam < attemt_num:
answer = input("> ") # Финишная прямая. Говорим комплементы, называем секретное число и спрашиваем, хочет ли игрок продолжить
if answer == 'no': print("You're done trying") # У тебя закончились попытки
print("Thanks for playing") print(f"The hiden numbers is {secret_num}.You want repeat the game? 'yes' or 'no'")
break answer = input("> ")
if answer == 'no':
print("Thanks for playing")
break
else:
print("You want repeat the game? 'yes' or 'no'")
answer = input("> ")
if answer == 'no':
print("Thanks for playing")
break