Hey everyone ! I’m in my first week at Codecademy and I love it so far! In between lessons I like experimenting with things I’ve learned and coupled with some help from googling things I finally got together a kilometre to mile conversion which also saves the output to a text file (I’m sure this is very simple for most but it’s a big step for me!).
My issue is, how can I change the following code where the output of miles (mi) gets rounded to 2 decimal places? I’ve tried using round() in so so many different ways and places with no luck …
km = float(input('Kilometers value: ')) factor = 0.62137119 mi = km * factor print('%0.2f kilometers is equal to %0.2f miles' %(km, mi)) output = str(mi) file = open('km_mile.txt','a') file.write(str(km) + ' kilometers is equal to ' + output + ' miles' + '.\n') file.close() if km == 0: break
I would love to know how to use round() in this case to only affect the output in the text file !
Thank you in advance to anyone who can help!