Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Display result with 2 decimal points, without 0 at the end

currently i get display:
cup’s to litre 0.30
but it needs to be 0.3

there is different unit conversion at the exercise, which need to be displayed with 2 decimal points

This is the code i have

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

tilavuus = float(input("Anna muunnettava tilavuus desimaalilukuna: "))

Cup_to_litra = tilavuus*0.24

print(f"Cup't muutettuina litroiksi: {Cup_to_litra:.2f}")
print()

Display:
Cup’t muutettuina litroiksi: 0.30

>Solution :

Try using f"Cup't muutettuina litroiksi: {Cup_to_litra:.2g}"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading