Python Forum
Can't figure out the syntax error, relatively simple code - 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: Can't figure out the syntax error, relatively simple code (/thread-11411.html)



Can't figure out the syntax error, relatively simple code - maho686868 - Jul-07-2018

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


RE: Can't figure out the syntax error, relatively simple code - buran - Jul-07-2018

there is missing closing parenthesis on line#2


RE: Can't figure out the syntax error, relatively simple code - MasterGame - Jul-08-2018

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.


RE: Can't figure out the syntax error, relatively simple code - volcano63 - Jul-08-2018

(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?'