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)
print "So, you're %s old, %s tall and %s heavy." %(
age,height,weight)
'''
Test Result:
How old are you?
31
How tall are you? 174
How much do you weigh?
80
So, you're '31' old, '174' tall and '80' heavy.
'''
心得:
%r 输出原始字符,用于调试,此处输出为’31‘
%s 输出字符串,此处输出31
int(raw_input()) 将其转换为整形数字
本文介绍了一个简单的Python程序,演示了如何使用raw_input()函数获取用户的年龄、身高和体重信息,并通过print语句输出这些信息。文章对比了%s和%r在输出时的区别,以及如何将输入转换为整数。
1853

被折叠的 条评论
为什么被折叠?



