Python: Print variable and string in same line

+1 vote

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 = 12346
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 is a birth every 7 seconds, there would be: " births "births"

Oct 30, 2018 in Python by findingbugs
• 3,140 points
68 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

For a better understanding you can refer the following link string formatting:

Use comma (,) to separate strings and variables while printing: eg

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

, in print statement separtes the items by a single space:

>>> print "abc","bcd","def"
abc bcd def
answered Oct 30, 2018 by Priyaj
• 56,140 points

Related Questions In Python

0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
1,186 views
0 votes
1 answer
+1 vote
1 answer

Print the odd and even factors of a number in Python

x = int(input("Enter any number \n")) print("The factors ...READ MORE

answered Nov 19, 2018 in Python by Nabarupa
151 views
0 votes
1 answer

How to handle AssertionError in Python and find out which line or statement it occurred on?

Use the traceback module: import sys import traceback try: ...READ MORE

answered Dec 17, 2018 in Python by charlie_brown
• 7,710 points
278 views
0 votes
1 answer

comparing strings in Python using "==" or "is"

is is used for identity testing and ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 10,940 points
23 views
0 votes
1 answer

Print Delimited list

You can try the following and see ...READ MORE

answered Feb 28 in Python by SDeb
• 10,940 points
18 views
0 votes
1 answer

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

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 56,140 points
37 views
0 votes
1 answer

*args and **kwargs in python

In cases when we don’t know how ...READ MORE

answered Jul 20, 2018 in Python by Priyaj
• 56,140 points
19 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.