0 votes
2 views
in Python

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 when I'm printing text either side of it?

Here is my code:

currentPop = 312032486

oneYear = 365

hours = 24

minutes = 60

seconds = 60

# seconds in a single day

secondsInDay = hours * minutes * seconds

# seconds in a year

secondsInYear = secondsInDay * oneYear

fiveYears = secondsInYear * 5

#Seconds in 5 years

print fiveYears

# fiveYears in seconds, divided by 7 seconds

births = fiveYears // 7

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

## 1 Answer

0 votes
by (106k points)

Yes, you can print variable and string on the same line in Python by using the below-mentioned code:-

print("If there was a birth every 7 second, there would be %d births." % (births))

To know more about this you can have a look at the following video tutorial:-

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer