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
78 views

1 answer to this question.

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,160 points

Related Questions In Python

0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered 4 days ago in Python by Neel
• 1,610 points
11 views
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,386 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
224 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
• 12,360 points
28 views
0 votes
1 answer

Print Delimited list

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

answered Feb 28 in Python by SDeb
• 12,360 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,160 points
43 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,160 points
24 views