Python Forum
Can't figure out the syntax error, relatively simple code
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't figure out the syntax error, relatively simple code
#1
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
Reply
#2
there is missing closing parenthesis on line#2
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply
#4
(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?'
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 329 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  Syntax error for "root = Tk()" dlwaddel 15 1,180 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 381 Jan-19-2024, 01:20 PM
Last Post: rob101
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 484 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Syntax error while executing the Python code in Linux DivAsh 8 1,586 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,228 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,316 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,257 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 891 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  help me simple code result min and max number abrahimusmaximus 2 908 Nov-12-2022, 07:52 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020