def number_of_legs():
print " The sparrow has how many legs"
legs = raw_input()
print "You said the sparrow has ",+ legs"legs"
number_of_legs()
答案 0 :(得分:3)
你忘记了串联加号:
print "You said the sparrow has " + legs + " legs"
尝试使用字符串格式:
print "You said the sparrow has {0} legs".format(legs)
答案 1 :(得分:3)
print " The sparrow has how many legs"
legs = raw_input()
print "You said the sparrow has {} legs".format(legs)
将输出:(如果腿是15)
You said the sparrow has 15 legs
另外,我建议你可以将一个字符串作为参数放到raw_input()
。像这样:
legs = raw_input("The sparrow has how many legs? ")
print "You said the sparrow has {} legs".format(legs)
当我运行时:
The sparrow has how many legs? 25 # 25 is my input and that's it
You said the sparrow has 25 legs
答案 2 :(得分:1)
def number_of_legs():
print " The sparrow has how many legs"
legs = raw_input()
print "You said the sparrow has, "+legs+"legs"
number_of_legs()
试试这个。只需要按顺序获取引号,加号和逗号。
答案 3 :(得分:1)
使用str.format
print "You said the sparrow has {0} legs".format(legs)