Reputation: 347
I am using Python 2.7... The problem I am facing is when i use this code
print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % (
age, height, weight)
The output comes to be -
How old are you? 35
How tall are you? 6'2"
How much do you weigh? 180lbs
So, you're '35' old, '6\'2"' tall and '180lbs' heavy.
But I don't want the single quotes that come in the 4th line of the output around 35, 180 lbs ang 6 2".. how to do
Upvotes: 0
Views: 236
Reputation: 5122
Dont use %r
. Change:
print "So, you're %r old, %r tall and %r heavy." % ( age, height, weight)
To:
print "So, you're %s old, %s tall and %s heavy." % ( age, height, weight)
The difference between repr()
and str()
is that repr()
is literal, and prints out the quotes with the string.
Here's an example in the interpreter:
>>> print '%r' % 'Hi' 'Hi' >>> print '%s' % 'Hi' Hi >>>
Upvotes: 8