@daria20022001

# Как сделать бесконечный цикл но только при ответе «yes»?

while True:
import random
print("-------Guess my number-------")
print("You need to guess the number picked by enigmatic computer!")
print("Number is in range from 1 to 10")
magic_number = random.randint(1, 10)
count = 0
user_number = 0
while user_number != magic_number:
count+=1
if magic_number > user_number:
print("The magic number is greater than yours!")
elif magic_number < user_number:
print("The magic number is less than yours!")
print("You Win! You guessed it on the", count,
"try")
while True:
print ("Want to play again?")
print ("Okay, see you later")
break
import random
print("-------Guess my number-------")
print("You need to guess the number picked by enigmatic computer!")
print("Number is in range from 1 to 10")
magic_number = random.randint(1, 10)
count = 0
user_number = 0
while user_number != magic_number:
count+=1
if magic_number > user_number:
print("The magic number is greater than yours!")
elif magic_number < user_number:
print("The magic number is less than yours!")
print("You Win! You guessed it on the", count,
"try")

нужно чтобы цикл продолжался только при ответе "yes"
• Вопрос задан
• 82 просмотра
Решения вопроса 1
@nvlveu
Не нужно создавать цикл в цикле)

Как-то так:
import random

count = 0

print("-------Guess my number-------")
print("You need to guess the number picked by enigmatic computer!")
print("Number is in range from 1 to 10")

user_number = None

magic_number = random.randint(1, 10)

while user_number != magic_number:
magic_number = random.randint(1, 10)

user_number = int( input("Your number: ") )
count += 1

if magic_number > user_number:
print("The magic number is greater than yours!")
elif magic_number < user_number:
print("The magic number is less than yours!")
print("You Win! You guessed it on the", count, "try")

print("Want to play again?")
print("Okay, see you later")
break
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

### Войдите, чтобы написать ответ

Похожие вопросы
Digital Security Санкт-Петербург
от 150 000 до 200 000 ₽
До 250 000 ₽
Skillbox Москва
от 200 000 до 230 000 ₽
19 янв. 2022, в 11:06
100000 руб./за проект
19 янв. 2022, в 10:47
1234 руб./за проект
19 янв. 2022, в 10:44
150000 руб./за проект