Python Forum
While True is a syntax error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While True is a syntax error?
#1
Hello everybody,

I am working on a little NON AI-Chatbot and I wanted to make a "while True:" loop inside a "if name == "main"". But when I'm running the code, it says:

while True: 
^ SyntaxError: invalid syntax
I've tried making another script with a while True loop, and that worked, but in the other script it just doesn't work.

Here's the nessacery code:
if __name__ == "__main__"

    #forever loop

    while True:

    #here are some if input things


    #this is the last piece of code, in the if__name__ ...

    elif input() in query ["That's not funny at all", "That was not funny", "Not funny."]:
            jokesorry = ["I am sorry.", "Sorry! :-("]
            print(random.choice(jokesorry))
Yes, so when I run the code, I'm getting a syntax error cause of that while True: as I've menshiond above. But what am I doing wrong about the while True:. Why am I getting an error. Thanks for your help guys. I am using python 3.7.

Piethon
Reply


Messages In This Thread
While True is a syntax error? - by Piethon - Jul-20-2019, 09:34 AM
RE: While True is a syntax error? - by perfringo - Jul-20-2019, 09:49 AM
RE: While True is a syntax error? - by metulburr - Jul-20-2019, 10:50 AM
RE: While True is a syntax error? - by Piethon - Jul-20-2019, 12:24 PM
RE: While True is a syntax error? - by perfringo - Jul-20-2019, 12:46 PM
RE: While True is a syntax error? - by metulburr - Jul-20-2019, 04:16 PM
RE: While True is a syntax error? - by Piethon - Jul-21-2019, 06:55 AM
RE: While True is a syntax error? - by buran - Jul-21-2019, 07:01 AM
RE: While True is a syntax error? - by metulburr - Jul-21-2019, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 233 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,354 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 458 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,772 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,309 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,380 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,336 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 954 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,949 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,432 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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