Python Forum
problem with syntax error - 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: problem with syntax error (/thread-4157.html)



problem with syntax error - jobemorgan - Jul-26-2017

I am just practicing with python and I keep getting invalid syntax pop up. I want it to end the script if the user says no. Please help!

print (" Hello, I will be asking you multiple questions to build a profile of who you are.")
answer = input ("Is this ok?")
if answer == ("no") 
import sys
sys.exit()
if awnser == ("yes")             
Name = input(" First of all, what is your name?")
print ("Ahh, hello " + Name )
Age = input ("Now " + Name + " What is your age? Now I must ask you enter this in numbers otherwise I will get confused")
Address = input ("What is your address?"



RE: problem with syntax error - sparkz_alot - Jul-26-2017

Typically, you put all imports at the top of you script.

You want to add a colon at the end of your if statements and indent the line after the if statement, also you don't need the parenthesis:

if answer == "no":
    sys.exit()



RE: problem with syntax error - sparkz_alot - Jul-26-2017

I'll also add, since your practicing, it is a good idea to avoid bad habits before they become habits, so familiarize yourself with this document: Python Style Guide

Make sure your closing parenthesis matches your opening parenthesis (see your line 10).
Use lower case for variable names, ie: name instead of Name, age instead of Age and so on.
Use 4 spaces (not tabs) for indentation.
Remember that input() will return a string, if you are looking for a number use something like int(input()), so this line:
Age = input ("Now " + Name + " What is your age? Now I must ask you enter this in numbers otherwise I will get confused")
would look like this:
age = int(input("Now " + Name + " What is your age? Now I must ask you enter this in numbers otherwise I will get confused"))
and would be much neater if you use formatting:
age = int(input("Now, {} what is your age? Now I must ask you enter this in numbers otherwise I will get confused".format(name)))
The same would be true for your print functions:
print("Ahh, hello {}".format(name))



RE: problem with syntax error - Larz60+ - Jul-26-2017

To elaborate on sparkz_alot:

Not sure what you are using for an IDE, but it may have something similar to PyCharm's inspect process.
This is a good tool to force yourself to use proper style, I use it on myself quite often (except at the
beginning of a project where my main goal is to get the code into the editor).