How can I print variable and string on same line in Python?

后端 未结 18 2122
面向向阳花
面向向阳花 2020-11-28 01:45

I am using python to work out how many children would be born in 5 years if a child was born every 7 seconds. The problem is on my last line. How do I get a variable to work

18条回答
  •  爱一瞬间的悲伤
    2020-11-28 02:08

    You can use string formatting to do this:

    print "If there was a birth every 7 seconds, there would be: %d births" % births
    

    or you can give print multiple arguments, and it will automatically separate them by a space:

    print "If there was a birth every 7 seconds, there would be:", births, "births"
    

提交回复
热议问题