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