Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The problem with my code is down below in the highlighted line with the syntax error. How would you format the indentation to fix the syntax of the code?

#Travies Robinson
#Coding Fundamentals : Coding Logic : 03.05 Python Project favorite video game response

def main():

 	answer = input("Would you like to take a one question survey? (yes or no)")
 	if(answer == "yes"):
 	 favGame = input("What is your favorite video game?")
	 print("Your favorite video game is the " + favGame + " amazing i've never played that
before.") - SyntaxError: bad input on line 16

	answer = input("What your favorite part of " + favGame + "?")
 	print("Interesting mabye i should try " + favGame + "."")
 	Country = input("What country are you living in right now?")
	print("You are currently living in " + Country + ".")
				Age = input("How old are you?")
				print("Your age is " + Age + ".")

	print("Thank you for answering the survey and have a great day!")

What I have tried:

I've tried re-indenting, going to various formatting sites. and uploading multiple questions. But they never worked for my specific code?
Updated 1-Nov-21 22:11pm

1 solution

Indentation is critical in Python: all items that are part of a block need to be indented to the same level, and your code doesn't do that.
The specific error is complaining about "Line 16" so go directly to that line - most editors will let you do that with CTRL+G - and you find this:
before.") - SyntaxError: bad input on line 16
at's an error because you clearly intended the word "before" to be a part of the string on the previous line:
     print("Your favorite video game is the " + favGame + " amazing i've never played that
STrings can't "cross lines" in Python unless you start and end them with triple quotes:
     print("""Your favorite video game is the " + favGame + " amazing i've never played that

And the indentation in your code is inconsistent: the if block ands after two lines, so the else doesn't match up with it, the code for the else block is not indented at all, and so on.

Pull it all back to the left hand side and go though indenting it properly, starting at the deepest block; use the same number of spaces for each indentation, don't mix 4 and 1 - use 3 or 4 consistently though the whole code.

And frankly your code lies: you ask for a "one question survey", and then ask four ...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900