Extra spaces when printing

后端 未结 4 1154
梦毁少年i
梦毁少年i 2021-01-28 06:05

I\'ve read through a number of the python whitespace removal questions and answers but haven\'t been able to find what I\'m looking for. Here is a small program that shows a sp

相关标签:
4条回答
  • 2021-01-28 06:18

    You need to format the entire line into a single string, then print that string.

    print ("\n\n\nOn the math section, you guessed {0}, and your actual score was {1}!".format(math_guess, math_score))
    
    0 讨论(0)
  • 2021-01-28 06:28

    Try this one:

    print "\n\n\nOn the math section, you guessed %d and your actual score was %d!" % (math_guess, math_score)
    

    You can read more at Built-in Types

    0 讨论(0)
  • 2021-01-28 06:34

    Yes, format your string:

    print("... you guessed {}, and ... was {}!".format(math_guess, math_score))
    
    0 讨论(0)
  • 2021-01-28 06:39
    print ("\n\n\nOn the math section, you guessed",math_guess,", and your actual score was",math_score,"!", sep ='')
    

    if this is py3+ i think

    print ("\n\n\nOn the math section, you guessed"+str(math_guess)+", and your actual score was"+str(math_score)+"!")
    

    should work if not

    or use string formatting as others have suggested...

    0 讨论(0)
提交回复
热议问题