• Welcome to Autism Forums, a friendly forum to discuss Aspergers Syndrome, Autism, High Functioning Autism and related conditions.

    Your voice is missing! You will need to register to get access to the following site features:
    • Reply to discussions and create your own threads.
    • Our modern chat room. No add-ons or extensions required, just login and start chatting!
    • Private Member only forums for more serious discussions that you may wish to not have guests or search engines access to.
    • Your very own blog. Write about anything you like on your own individual blog.

    We hope to see you as a part of our community soon! Please also check us out @ https://www.twitter.com/aspiescentral

Python print bug ?

GoofKing

All your bases are belong to us
I think there's a bug in the Python print function where you have position your double quotes in the right amount of spaces or else it'll give you an error ...

For example, this is the source for an adult-like text adventure/RPG game that I'm creating as I learn python.

# I just want to get laid is a game about a poor man
# getting trapped in another dimension on his way to
# do his girlfriend.
# You must save the beings from evil invaders before
# going back
#

game_intro = """

+++++++++++++++++++++++++++++++++
= I JUST WANT TO GET LAID!!!! =
+++++++++++++++++++++++++++++++++
"""

print game_intro

# Game intro prints, now get players name
#

playername = raw_input('Enter your name: ')

# Display game's objections

print "Welcome " + playername

# TODO: See about adding a list of commands to print for the player
# Write a cool intro story so that the player knows what's happening
#
# Print out story

print """

+======================================+
+ On your way to see your girlfriend +
+ You pick up a box of condoms for +
+ the special night you and the love +
+ of your life had planned together, +
+ +
+ seeing how this is your anniversity +
+ today and you were too cheap to +
+ afford her roses, candy or a teddy +
+ bear ... +
+======================================+

"""
input("Press Enter to continue...")
print """
+======================================+
+ But fate is a cruel thing, who's +
+ mean enough to prevent you from +
+ such dirty deeds you were so +
+ looking forword to tonight becau- +
+ es suddenly .... +
+======================================+
"""


input("Press Enter to coninue...")
print """

+================================+
+ You get sucked into a wormhole!+
+================================+
"""

So would anyone know why this:

print """

+======================================+
+ On your way to see your girlfriend +
+ You pick up a box of condoms for +
+ the special night you and the love +
+ of your life had planned together, +
+ +
+ seeing how this is your anniversity +
+ today and you were too cheap to +
+ afford her roses, candy or a teddy +
+ bear ... +
+======================================+

"""
input("Press Enter to continue...")
print """
+======================================+
+ But fate is a cruel thing, who's +
+ mean enough to prevent you from +
+ such dirty deeds you were so +
+ looking forword to tonight becau- +
+ es suddenly .... +
+======================================+
"""

Is showing up as all green in nano while the other print functions escape the color to show that it knows what it is needing to print ?

Also the input functions (I think) are giving an error as well ...

Is a bug with the language or is there a typo/mistake I'm not catching ? I've had the weird bug happen before where python complained about double quotes not being in the right spot ...


 
What version on python are you using? The syntax differs between many of the versions sadly, so its often hard to distinguish syntax errors without knowing the version number.
 
What version on python are you using? The syntax differs between many of the versions sadly, so its often hard to distinguish syntax errors without knowing the version number.

According to the command line, I'm using version 2.7.3 :/
 
Ah okay, its one of my favourite versions of Python, I never was much of a fan of 3.0 or anything later.
So far I can see one error, and thats with how you've used the "input" command.

Your code: input("Press Enter to continue...")
How I think it should be: var = raw_input("Enter text here: ")

Where the var should be the variable name, perhaps testing if "var" is equal to 'y' or 'n' could be a more logical way of going about the programming solution - at least that's what I would do. I am however, absolutely sure, that leaving the input undefined is the cause of the error. :)

Hope I helped you out.

Edit: the user input could also be used here, and is probably more practical, though, the raw_input function should still do the job.
 
Mind Blowing Information (At least I found it mind blowing...I'm not sure who else has this much enthusiasm for coding):

'Raw input' should be used for Python 2, while simply 'input' should be used with Python 3. *The more you know*

Sooooo...seeing as your using a Python 3 function,I analyse that your most likely following a Python 3 course (which has different function names and methods), therefore, it is my suggestion to check whatever course your following and download the appropriate version of Python so you don't get confused :)

Of course though, input or raw_input, you still need to store the value from the input into a variable.
 
Last edited:
It's not just python, its pretty common. I've seen it a long time ago on a zx spectrum :)

Print "...." Prints .... Characters. If you want to actually print a " then you need to put """ in as its the central " which is the character to be printed.

Its not a bug, its just a logic thing :)
 
It's not just python, its pretty common. I've seen it a long time ago on a zx spectrum :)

Print "...." Prints .... Characters. If you want to actually print a " then you need to put """ in as its the central " which is the character to be printed.

Its not a bug, its just a logic thing :)

As far as I'm aware, how he's printing the strings is quite fine :/ (While it appears awkward, I've also tested it and it seems to function correctly; the only error being how hes grabbing the input)
 
As far as I'm aware, how he's printing the strings is quite fine :/ (While it appears awkward, I've also tested it and it seems to function correctly; the only error being how hes grabbing the input)

Ahh, yup point taken. I was just mentioning my experience of the old "how to print a " problem" back in the day. Input grabbing syntax is the next one on the list. ;)

I skimmed the post so might have missed that :)
 
I hope I'm understanding your question correctly. I think that print """ (three double quotes) won't work. You either need to enclose the double quote in single quotes or escape the middle one with a backslash.

# two double quotes returns empty string
print ""

# this tells the interpreter to not count the middle quote as an instruction instead of closing the first quote
print "\""

# you can use single quotes to enclose the double quote and that will work
print '"'

# if you have three double quotes, Python will think that you're quoting one string (the empty string between the first two quotes) and then opening up a second quote with the third double quote -- it's an unfinished statement
# this example shows how print can accept multiple quoted strings
print "a" "b"

python-example.png
 
Oh... I just reread this. Ignore my post above. For some reason, I thought that your code was just trying to print a quote sign:

print """

My eyes glazed over the rest, because it wasn't Python syntax:

+======================================+
+ On your way to see your girlfriend +
+ You pick up a box of condoms for +
+ the special night you and the love +
+ of your life had planned together, +

Visual processing error... :confused:
 

New Threads

Top Bottom