how to get the product after the colons

49 views Asked by At

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
4

There are 4 answers

0
Hugo Guillen On BEST ANSWER

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)
0
Ajay A On

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
0
Maran Sowthri On

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)
0
Booboo On

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