I am self teaching myself python and I have hit a question that I can't seem to figure out dealing with raw_input.

This is the code that is confusing me:

print "How tall are you?",
height = raw_input()

print "So, you're %r tall ." % (height)

I input my height as 5' 10" and get the follwing output:

How tall are you? 5' 10"
So, you're '5\' 10"' tall .

What am I missing from my code to fix the output so it reads properly?

TrustyTony commented: Great first post/thread +12

%s, not %r: str not repr.

height = raw_input("How tall are you? ")   
print "So, you're %s tall." % height

Thanks!

As a follow question, why does %s work and not %r?

%r is repr, the official representation, which can be evaluated to yield the same value of same type. In case of strings it includes the quotes.

%s is str, the output for humans form, which does not include quotes/escapes.

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.