0

Help me!

a=3.1874828 How to print to the screen 3.18

10th Feb 2017, 6:38 AM
School Dog
4 Respuestas
+ 5
a = 3.1874828 print('{0:.2f}'.format(a))
10th Feb 2017, 7:13 AM
Igor B
Igor B - avatar
+ 1
a=3.1874828 # If print(3.18) is not an option # you can use string slicing print(str(a)[:4])
10th Feb 2017, 7:03 AM
richard
+ 1
ms arnold round gives 3.19 not 3.18 as required
11th Feb 2017, 7:04 AM
richard
+ 1
# no problem ms arnold, it's worth experimenting # with code there is usually multiple solutions. a=3.1874828 print(int(a*100)/100) # or a = 3.1874828 print(((a/.01)//1)/100)
11th Feb 2017, 10:49 AM
richard