0

so im learning this program BMI calculator, and i want the answers to be written after the ':', not under it. can anyone help me pls? is it even possible to get that type of answer?

heres the code:

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi:")
print(bmi)
if bmi < 25:
    print(name)
    print("is not overweight")
else:
    print(name)
    print("is overweight")

#printed:
bmi:
27.5
hello
is overweight

#but what i want is this:
bmi: 27.5
hello is overweight
  • Does this answer your question? [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) – Harun Yilmaz Sep 28 '20 at 10:42

4 Answers4

0

Try this

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi: {}".format(bmi)
if bmi < 25:
    print("{} is not overweight".format(name))
else:
    print("{} is overweight".format(name))

#prints:
bmi: 27.5
hello is overweight
Ajay A
  • 1,030
  • 1
  • 7
  • 19
0

You need to put a comma in the same print statement instead of two separate ones.

print("bmi:",bmi)

instead of

print("bmi:")
print(bmi)
Hugo Guillen
  • 126
  • 6
0

Try this,

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi:", end=' ')
print(bmi)
if bmi < 25:
    print(name, end=' ')
    print("is not overweight")
else:
    print(name, end=' ')
    print("is overweight")

Or you can put everything in a single print statement like this,

print(name, "is overweight")
print("bmi:", bmi)
Maran Sowthri
  • 829
  • 6
  • 14
0

You can either do:

print("bmi:", bmi) # the simplest

or

print(f"bmi: {bmi}") # f string in Python 3

or

print("bmi: ", end="") # Your original code, modified
print(bmi)

or

print("bmi: %s " % bmi) # too extreme -- don't do it for this simple case

or

print("bmi: {}".format(bmi)) # too extreme
Booboo
  • 38,656
  • 3
  • 37
  • 60