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,200 points
220 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
• 57,530 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 Jul 15, 2019 in Python by Neel
• 3,010 points
90 views
+1 vote
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
3,696 views
0 votes
1 answer

What's the right way to concatenate files and appending the New Line character in Python? Text or binary mode?

It seems like you're using the wrong ...READ MORE

answered Nov 13, 2018 in Python by Anirudh
• 2,080 points

edited Dec 14, 2018 by Anirudh 173 views
+3 votes
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
1,925 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
• 13,230 points
63 views
0 votes
1 answer

Print Delimited list

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

answered Feb 28, 2019 in Python by SDeb
• 13,230 points
128 views
0 votes
1 answer
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
• 57,530 points
208 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
• 57,530 points
84 views