Printing out an answer in quotes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thekid
    New Member
    • Feb 2007
    • 145

    Printing out an answer in quotes

    Hi, how can I get an answer to print out in quotes? Example is of a math question in which the answer prints out in this format:
    print answer
    >>>15

    The answer varies with each question and I'd like it to print out like this:
    >>>'15'

    How can I get the quotes added in? Thanks
  • Thekid
    New Member
    • Feb 2007
    • 145

    #2
    I think I figured it out:

    Code:
    print " '%s' " % answer

    Comment

    • dazzler
      New Member
      • Nov 2007
      • 75

      #3
      you can print it also this way:

      [code=python]
      print " ' ", answer, " ' "
      [/code]

      Comment

      • elcron
        New Member
        • Sep 2007
        • 43

        #4
        You can escape quotes with "\" but it usually better to avoid it unless you're nesting multiple layers of quotes.
        [code=python]
        >>> print "\""
        "
        >>> answer = 15
        >>> print "\"%s\""%(answe r)
        "15"
        [/code]

        Comment

        Working...