Вопрос задан 01.10.2023 в 06:29. Предмет Информатика. Спрашивает Мырзатай Али.

Вот у меня есть программа не понимаю в как сделать помогите пж смотрите если пользователь вводит

неправильное число то есть число не равно 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!")
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Алибекова Мадина.

Ответ:

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")

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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:

python
import 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:

  1. The first input is handled as you originally did for the first level.
  2. If the user does not guess correctly in the first level, they will be asked to enter another number (i2) for the second level.
  3. 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.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос