Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make it display what I need after the condition is met

Here is my code:

start_bot=input("Enter '/start' to start the bot: ") 
while start_bot!=("/start"): 
  print (input("Enter start!")) 
  if start_bot==("/start"): 
    print("Welcome!") 

If you run and type "/start" it will display "welcome". If you run and type "/non-start" it will display "Enter start", then I will type "/start" and run and it will display "Enter start" again. What’s the problem?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I guess you need to set the last conditional statement out of the loop, and reassign the start_bot variable inside it:

start_bot=input("Enter '/start' to start the bot: ") 
while start_bot!=("/start"): 
  start_bot=input("Enter start!")
print("Welcome!") 

Output

Enter '/start' to start the bot: /no
Enter start!/start
Welcome!
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading