Python Forum

Full Version: Can't figure out the syntax error, relatively simple code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I started learning python a few days ago and decided to code something that happened yesterday, I wanted to print a quote and then input a question to answer, however the console rejects it and only allows me to do it if I make sure the first line is the input. My inputs are shown below:

#testing inputs and strings
print("Realf:'Shar, what ride you wanna go on after we eat?'"
first = (input("Shar-Shamar Steward, RB is asking what ride you would like to go on?"))
print("\n Maho:'Ite. You man lets go queue up for", first, "'")
import time
time.sleep(2)
print("\n\ntwo hours later...", end='')
time.sleep(1.5)
print("\n\n...Hydajet'FAM...FAAMMMM we've been here for two hours cos of this retard when we could've gone on saw how many times for **** sake")


input("\n\n\npress enter key to exit")
Thank you so much for any help
there is missing closing parenthesis on line#2
You used this: print("Realf:'Shar, what ride you wanna go on after we eat?'"
When it should be this: print("Realf:\'Shar, what ride you wanna go on after we eat?\'")
There is a missing parentheses at the end of the string, and the backslashes (\) before the single quotes (') are necessary. Otherwise, Python thinks the string ends when it hasn't finished yet.
(Jul-08-2018, 03:38 PM)MasterGame Wrote: [ -> ]When it should be this: print("Realf:\'Shar, what ride you wanna go on after we eat?\'")

No need for backlashes - within double quotes, single quotes don't need to be escaped.

Output:
In [10]: print("Realf:'Shar, what ride you wanna go on after we eat?'") Realf:'Shar, what ride you wanna go on after we eat?'