Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

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:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...