Python Forum

Full Version: Simple syntax error help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im new to programming in general and am playing with the water. I seem to have hit a syntax error that I just cannot figure out why.

person = input('Enter your name: ')
print('Hello', person)
ask = input('What would you like me to do for you today')
if ask : "Tell me a joke"
print('Caroline has a small nostril')
else:
According to the ide(pycharm) the error message looks like this according to line 6:
else:
^
SyntaxError: invalid syntax

Also what is the best way to go about going back to line 3 after the else command, couldnt test it out cause I couldnt get passed it!

Any help is appreciated!
i'm new myself but i can offer one small correction

if ask=="Tell me a joke":
print('Caroline has a small nostril')

as for asking the question again, you can use a while statement.
something like this:

while True:
ask=input("")
if ask==" ":
break

maybe someone can give a better answer, but that was what i could think of.
Sometimes error is on previous line(s). In this case - on line 4. But even after you fix it, indentation on line 5 is incorrect and you need something on line 9 (i.e. body of the else clause)

person = input('Enter your name: ')
print('Hello', person)
ask = input('What would you like me to do for you today')
if ask == "Tell me a joke":
    print('Caroline has a small nostril')
else:
    print('Really, Caroline has a small nostril')
(Aug-02-2017, 08:40 AM)wikedkid Wrote: [ -> ]if ask=="Tell me a joke":
print('Caroline has a small nostril')
while True:
ask=input("")
if ask==" ":
break
I tried this but it says indentation error for break but when i indent it it says it breaks the loop

(Aug-02-2017, 08:41 AM)buran Wrote: [ -> ]Sometimes error is on previous line(s). In this case - on line 4. But even after you fix it, indentation on line 5 is incorrect and you need something on line 9 (i.e. body of the else clause

I originally tried it with the == on line 4 it still says invalid syntax

EDIT: I dunno why but I retried your way and it worked the second time, maybe a typo i didnt notice in my correcting it, what i want the else to do is loop it back to a previous spot in the code like before or after the Enter your name part
You need to put the part of code that you want to repeat in a loop. try to do it yourself and ask again if you face problem.