
Вот у меня есть программа не понимаю в как сделать помогите пж смотрите если пользователь вводит
неправильное число то есть число не равно 16 ему прделаагеться ввести еще раз, но у меня даже если о угадал число ему снова предлагаеться ввести это число помогите пж d = 16 i=int(input('Your select(print number 1 to 18):')) if i == 16: print("You completed 1 level") flag =['.*+==+*:... ', '.*++=%%======+*:.... ', '.*++++=%%%%%========+*:-.... ', '.*+==++++=%%@@%%=========+++++**:-...... ', '.*+====++++++=%@@@%%==++======+++++++====+*:... ', '.*++=%%==+++++++=%%@@@@%%=++======+++++=========+*:--... ', '.*++==%%%==+++++++===%%@@@@%%==++======++++======+*****+. ', '.*+++==%%%====++++++=%%===%%@@@%%=++++====++*+++=+++*****.', '.*==+++==%%%====+*++++=%%%==++=%@@@@%==+*+====+**++==++**.', '.**++***+==%%%====+*++++=%%%%=+==+=%@@@%%%+**+===+**++++*.', '.:**+**::::***+++***:::***+=%%%%=+==++=%@@%%%=+**+==+*+++.', '.:::*++***:::***++++**::::::*++===+**+=++=%%%%%%=+**==+*: ', '.:**:**+++**::::***+++**::::::**+==++*::****+=%%%%%=**==: ', '.:**:::**+++**::::**+++**:::::::*++===+*::***:*+====%=**+.', '.:***::::*++++*:::::**+++**:::::::*+====+*::***:*+===++*:.', '.:****::::**+++*:::::***+****:::::::*+====+*::***:*+===+: ', '.:***+*::::*++++*:::::*********:::::::*+====+*::***::+++. ', '.:****+*::::*+++**::::***********:::::::*=====+*::***:::. ', '.::***+**:::*++++*::::**************::::::*=====+**::*:: ', ' :. .....----::***************:::**:*=====++*::*. ', ' :. ..........-:::*=====+**:- ', '.:. ..:==+*- ', ' :. ..-. ', '.:. ', '.:. ', ' :. ', '.:. ', ' :. ', '.:. ', ' :. ', ' :. ',] for i in range(len(flag)): print(flag[i]) time.sleep(.1) elif i != 16: print("You Lose. Try again!") smile =['#####################################', '###########@#@@@@@@@@@@@@#=##########', '#########@@@@#%**+++**=#@@@@@@#######', '#######@@@++*...........:+*#@@@######', '#####@@#*+.................-+%@@@@###', '####@@*+---------------------:+#@@###', '##@@@*+:::::::::::::::::::::::++#@@##', '##@@++**::::::#::::::::#:::::**++#@@#', '##@#++***=##%-=@******@%-%##=**++=@@#', '#@@@++****+=+++=******%===+*****++@@#', '#@@@++****#####%******%#####****++@@#', '##@#++***:%@##:********:#@%%***++@@@#', '##@@@++%***@**************%***++*@@@#', '###@@%=+.-*%***%######=***%:..+=@@@##', '####@@+*:*=%***+:*****+***@+*:+=#@###', '######%%%@%**************++@%%%@#####', '########@@@@+**+%****+**++#@@@#######', '###########@@@@@@@%=@@@@@@@##########', '###############@#@@#@################',] for i in range(len(smile)): print(smile[i]) time.sleep(.1) n = 12 i2=int(input('Your select(print number 1 to 10):')) if i2 == 8: print("You completed 2 level") elif i2 >= 11: print("Error. Try again!") elif i2 != 8: print("You Lose. Try again!")

Ответы на вопрос

Ответ:
flag =['.*+==+*:... ',
'.*++=%%======+*:.... ',
'.*++++=%%%%%========+*:-.... ',
'.*+==++++=%%@@%%=========+++++**:-...... ',
'.*+====++++++=%@@@%%==++======+++++++====+*:... ',
'.*++=%%==+++++++=%%@@@@%%=++======+++++=========+*:--... ',
'.*++==%%%==+++++++===%%@@@@%%==++======++++======+*****+. ',
'.*+++==%%%====++++++=%%===%%@@@%%=++++====++*+++=+++*****.',
'.*==+++==%%%====+*++++=%%%==++=%@@@@%==+*+====+**++==++**.',
'.**++***+==%%%====+*++++=%%%%=+==+=%@@@%%%+**+===+**++++*.',
'.:**+**::::***+++***:::***+=%%%%=+==++=%@@%%%=+**+==+*+++.',
'.:::*++***:::***++++**::::::*++===+**+=++=%%%%%%=+**==+*: ',
'.:**:**+++**::::***+++**::::::**+==++*::****+=%%%%%=**==: ',
'.:**:::**+++**::::**+++**:::::::*++===+*::***:*+====%=**+.',
'.:***::::*++++*:::::**+++**:::::::*+====+*::***:*+===++*:.',
'.:****::::**+++*:::::***+****:::::::*+====+*::***:*+===+: ',
'.:***+*::::*++++*:::::*********:::::::*+====+*::***::+++. ',
'.:****+*::::*+++**::::***********:::::::*=====+*::***:::. ',
'.::***+**:::*++++*::::**************::::::*=====+**::*:: ',
' :. .....----::***************:::**:*=====++*::*. ',
' :. ..........-:::*=====+**:- ',
'.:. ..:==+*- ',
' :. ..-. ',
'.:. ',
'.:. ',
' :. ',
'.:. ',
' :. ',
'.:. ',
' :. ',
' :. ']
smile =['#####################################',
'###########@#@@@@@@@@@@@@#=##########',
'#########@@@@#%**+++**=#@@@@@@#######',
'#######@@@++*...........:+*#@@@######',
'#####@@#*+.................-+%@@@@###',
'####@@*+---------------------:+#@@###',
'##@@@*+:::::::::::::::::::::::++#@@##',
'##@@++**::::::#::::::::#:::::**++#@@#',
'##@#++***=##%-=@******@%-%##=**++=@@#',
'#@@@++****+=+++=******%===+*****++@@#',
'#@@@++****#####%******%#####****++@@#',
'##@#++***:%@##:********:#@%%***++@@@#',
'##@@@++%***@**************%***++*@@@#',
'###@@%=+.-*%***%######=***%:..+=@@@##',
'####@@+*:*=%***+:*****+***@+*:+=#@###',
'######%%%@%**************++@%%%@#####',
'########@@@@+**+%****+**++#@@@#######',
'###########@@@@@@@%=@@@@@@@##########',
'###############@#@@#@################']
import time
i = 0
while i != 16:
i = int( input( 'Your select(print number 1 to 18): '))
if i != 16:
print("You Lose. Try again!")
for i in range(len(smile)):
print(smile[i])
time.sleep(.1)
print("You completed 1 level")
for i in range(len(flag)):
print(flag[i])
time.sleep(.1)
i2=0
while i2 != 8:
i2 = int( input( 'Your select(print number 1 to 10):'))
if i2 >= 11:
print("Error. Try again!")
if i2 != 8:
print("You Lose. Try again!")
print("You completed 2 level")



The issue you are facing is due to the logic of your code. You have two input sections, one for the first level (using the variable i
) and another for the second level (using the variable i2
). However, you are not correctly handling the second level input. Here's a modified version of your code that should work as you described:
pythonimport time
d = 16
i = int(input('Your select (print number 1 to 18): '))
if i == d:
print("You completed 1 level")
flag = [
'.*+==+*:... ',
# (Rest of your flag patterns)
]
for i in range(len(flag)):
print(flag[i])
time.sleep(0.1)
elif i != d:
print("You Lose. Try again!")
smile = [
'#####################################',
# (Rest of your smile patterns)
]
for i in range(len(smile)):
print(smile[i])
time.sleep(0.1)
i2 = int(input('Your select (print number 1 to 10): '))
if i2 == 8:
print("You completed 2 level")
elif i2 >= 11:
print("Error. Try again!")
elif i2 != 8:
print("You Lose. Try again!")
In this modified code:
- The first input is handled as you originally did for the first level.
- If the user does not guess correctly in the first level, they will be asked to enter another number (
i2
) for the second level. - The second level logic checks if
i2
is equal to 8 to complete the level or if it's greater than or equal to 11 to show an error message. If it's not 8 and not greater than or equal to 11, it means the user didn't guess correctly in the second level.
This code should address the issue of the program continually asking for input even if the user has guessed correctly.


Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili