P
P
python_bonobo2021-11-19 12:49:06
Python
python_bonobo, 2021-11-19 12:49:06

How to loop my super python code?

Hello.
how can i loop it? please help;(
so that every time when the user answers n / N it would return to the then line
and so on in a circle until the answer is yes.
I can’t understand at all, I looked at the examples, but I don’t catch the logic.

1 number = input( "Type your number here:")
2 print("your number is:"+ str(number))
3 yournumber = input("Right number? (Y/N): ")
4 then = input("Type your number again : ")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kir Mozor, 2021-11-20
@python_bonobo

#Бесконечный цикл. Цикл while работает если он True
while True:  
  #Вводим данные
  number = input("Type your number here:")
  #Выводим
  print("Your number is:" + str(number))
  #Просим ввода
  yournumber = input("Right number? (Y/N):")
  #Если пользователь ввёл y или Y волшебное слово break останавливает цикл. Если if не сработал, цикл повторяется снова
  if yournumber == "y" or yournumber == "Y":
    break

Cycles are well described here :

R
Ronald McDonald, 2021-11-19
@Zoominger

Write an infinite loop, the exit condition from which will be:
yournumber == 'Y'
You can exit the loop using break .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question