Python Forum
Program doesnt return beginning - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Program doesnt return beginning (/thread-39425.html)



Program doesnt return beginning - bilisim19 - Feb-15-2023

num=int(input("age:" ))

if num>18:
    print("old")
else:
   print("young")
When this code is first running there is no problem, but entering second input , print only data value instead condition statement


RE: Program doesnt return beginning - deanhystad - Feb-15-2023

I do not understand the question. Your code provides no way to enter a second input. You run the program. The program waits for you press the enter key. The program converts whatever you typed into an int. If the int is > 19 the program prints "old", otherwise it prints "young". Execution reaches the end of the program, and the program ends.

Do you want to repeat the code? (get input, print...)? To do that you need some kind of loop (for or while).


RE: Program doesnt return beginning - Larz60+ - Feb-15-2023

how did you run the second time.
The way your code is structured, it will run once then exit program.

In order to continue, you need to create a loop.
Then, if you create a loop, you should also create a condition that will allow you to exit the loop.