Python Forum
Program doesnt return beginning
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program doesnt return beginning
#1
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
Larz60+ write Feb-15-2023, 06:21 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.

(I also fixed incorrect indent)
Reply
#2
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).
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Just beginning dalekeel 2 262 Apr-15-2024, 11:49 AM
Last Post: Pedroski55
  List of dataframe values beginning with x,y or z glidecode 3 1,964 Nov-08-2021, 10:16 PM
Last Post: glidecode
  How to start the program from the beginning. iamaghost 5 2,983 Feb-23-2021, 03:40 AM
Last Post: deanhystad
  I have two Same Code but One of them Doesnt Work beginner721 6 3,139 Jan-22-2021, 10:56 PM
Last Post: beginner721
  code doesnt return anything ofrihemo 3 2,063 Jun-30-2020, 05:14 PM
Last Post: ofrihemo
  want to change the beginning of the result Rudinirudini 5 3,611 Nov-15-2018, 11:28 AM
Last Post: Rudinirudini
  why doesnt the while loop run? supermane 3 3,127 Aug-04-2018, 06:01 AM
Last Post: wavic
  Beginning of Beginner Help: Should I start with Python? appdevelnewb 2 3,079 Jul-23-2018, 11:17 PM
Last Post: appdevelnewb
  Wrap from end to beginning. 27 to 1, 28 to 2 etc DreamingInsanity 5 3,721 Jun-24-2018, 01:02 PM
Last Post: ljmetzger
  Why does this work and this doesnt= puruvaish24 1 2,614 May-22-2018, 03:58 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020