-3

I am a beginner.

How do I print multiple expressions in Python 3 on the same line.

Here is some simple code I wrote for a class exercise in my beginner class:

temp = int (input ("What is the outside temperature? "))
if temp < 70:
  print ("Wear a jacket ")
else:
  print ("No jacket is necessary ")
print ("when you go outside.")

If I input 50 degrees, the output says:

"Wear a jacket
when you go outside."

whereas I want it to read:

"Wear a jacket when you go outside."
Matt
  • 11
  • 1
  • 6

1 Answers1

0

You can pass multiple values to print() separated by commas.

print(value_1, value_2, value_3)

Marios Keri
  • 98
  • 1
  • 8
  • Ok but the first value I'm printing is dependent on the "if" and "else" statements, whereas the second value is separate and gets printed no matter what. Do I need to write it twice (once in the "if" portion and once again in the "else" portion of the code)? – Matt Mar 08 '20 at 00:19
  • You can use it like this `print("Wear a jacket ", end=' ')` for both print in if else. – Marios Keri Mar 08 '20 at 00:32