控制小数点/位输出的数量

时间:2019-05-03 22:48:25

标签: python

我正在研究一个作业问题,该问题基本上要考虑一些有关输出区域尺寸的值。我真正挣扎的唯一部分是,我的硬件站点上的解释器只想要小数点后一位。我正在使用float,并且按预期得到许多小数点。有谁知道小数点后只输出一个十进制值?

我真正尝试过的唯一一件事就是更改数据类型int,float,double。但是我知道有一个格式化选项可能会有所帮助,但我们还没有介绍,因此我想在不使用该方法的情况下解决它


wallHeight = float(input('Enter wall height (feet): \n'))

wallWidth =  float(input('Enter wall width (feet): \n'))

wallArea = float(wallHeight * wallWidth)

print('Wall area: %f ' % wallArea + 'square feet')



# FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall

gallon_paint = 350

paint_coverage = float(wallArea/(gallon_paint))

print('Paint needed: %f ' %paint_coverage)



# FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer

cans_of_paint = int(paint_coverage) + 1

print('Cans needed: %d'%cans_of_paint + ' can(s)')



# FIXME (4): Calculate and output the total cost of paint can needed depending on color



color = input('Choose a color to paint the wall:')
color_chosen = int(paint_colors.get(color))
cost = int(color_chosen * cans_of_paint)

price = 'Cost of purchashing ' + color +' paint: ' + str(cost)

print(price)

0 个答案:

没有答案