String Formatting with %, Part 1 Invalid syntax


#1

Link to the exercise:
https://www.codecademy.com/courses/python-beginner-sRXwR/3/3?curriculum_id=4f89dab3d788890003000096

The codecademy works fine. I just tried the exact same code on python and it gives:
SyntaxError: multiple statements found while compiling a single statement

I tried it with the ' in the code like in the exercise. I tried to backslash them, and completly with out them.
Cant figure out whats wrong

string_1 = "Camelot"
string_2 = "place"

print "Lets not go to %s. Tis a silly %s." %(string_1, string_2)

#2

Hi @laatikkofrank ,

Were you trying to run it in IDLE? If you copy and paste the whole program into the interactive window, this is what happens ...

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> string_1 = "Camelot"
string_2 = "place"

print "Lets not go to %s. Tis a silly %s." %(string_1, string_2)
SyntaxError: multiple statements found while compiling a single statement
>>>

You can enter one line at a time in interactive mode. If you want to enter more than one line of code at the same time, it needs to be pasted into the editor instead.

To run it as a program in IDLE, then from the IDLE menu, choose ...

File > New File

Then, paste your code into the editor. Save it as a .py file. Then, from the menu, choose ...

Run > Run Module

If you are using Python 3, remember to adapt it for that version. This includes invoking print as a function, rather than as a command, for example ...

print("Lets not go to %s. Tis a silly %s." %(string_1, string_2))

There are other differences, as well. See Porting Python 2 Code to Python 3.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.