Refracting. Instead of the basic while loop, a for loop
This commit is contained in:
parent
90ed40714f
commit
3d1a9d7a8b
23
main.py
23
main.py
|
@ -5,17 +5,13 @@ max_nam = 10
|
|||
guess_num = 3
|
||||
|
||||
|
||||
def create_secret_num():
|
||||
def create_secret_num(guess_num):
|
||||
"""Создание случайного числа"""
|
||||
digits = list('0123456789')
|
||||
random.shuffle(digits)
|
||||
secret_num = ''
|
||||
for i in digits[0:3]:
|
||||
secret_num += i
|
||||
print(secret_num)
|
||||
return secret_num
|
||||
return ''.join(digits[:guess_num])
|
||||
|
||||
def attempt_check():
|
||||
def attempt_check(attemt):
|
||||
clue = []
|
||||
for i in range(len(attemt)):
|
||||
|
||||
|
@ -23,13 +19,13 @@ def attempt_check():
|
|||
clue.append("Fermi")
|
||||
if attemt[i] in secret_num:
|
||||
clue.append("Pico")
|
||||
return ''.join(clue)
|
||||
return ''.join(clue) if clue else 'Bagle'
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
for attempt_num in range(1, max_nam + 1):
|
||||
"""Основной цикл для прекращения или повторения игры"""
|
||||
secret_num = create_secret_num() # Создание случайного числа
|
||||
secret_num = create_secret_num(guess_num) # Создание случайного числа
|
||||
print("I meade a number.") # По сути, не нужное оповещение о создание числа(Создано для игрока)
|
||||
attemt_num = 1 # Номер попытки игрока
|
||||
|
||||
|
@ -51,11 +47,8 @@ while True:
|
|||
print("You win!")
|
||||
break
|
||||
|
||||
clue = attempt_check() # А вот и подсказка
|
||||
if len(clue) == 0:
|
||||
print("Bagle")
|
||||
else:
|
||||
print(clue)
|
||||
print(attempt_check(attemt)) # А вот и подсказка
|
||||
|
||||
attemt_num += 1
|
||||
|
||||
if max_nam < attemt_num:
|
||||
|
|
Loading…
Reference in New Issue