我正在编写一个油漆程序,该程序应该确定用矩形地板绘制棚屋墙壁的成本。我应该假设棚子没有窗户,油漆成本是每加仑40美元。一加仑占地300平方英尺。我想提示用户输入棚屋的尺寸。我还应该使用一个名为paint_cost的函数,它将用户输入作为参数,并返回绘制棚屋墙壁的成本。最后,我必须以货币格式表达成本。
我可以说服用户输入尺寸,但是在他们输入尺寸并点击输入后,它会转到>>>我试图找出我在这里做错了什么以及如何解决它以便正确运行。
def main():
wall1 = float(input('enter length of wall 1: '))
wall2 = float(input('enter length of wall 2: '))
wall3 = float(input('enter length of wall 3: '))
wall4 = float(input('enter length of wall 4: '))
wall_height = float(input('enter height of walls: '))
combine_walls1 = wall1 + wall2
combine_walls2 = wall3 + wall4
def paint_cost(combine_walls1, combine_walls2):
combined_walls = combine_walls1 + combine_walls2
Square_foot = combined_walls * wall_height
gallon = Square_foot / 300
cost = gallon * 40
print('total: $', format(paint_cost, ' ,.2f'))
main()
答案 0 :(得分:0)
paint_cost
未被调用。paint_cost
应该收到wall_height
。cost
中打印paint_cost
而不是paint_cost
。def main():
wall1 = float(input('enter length of wall 1: '))
wall2 = float(input('enter length of wall 2: '))
wall3 = float(input('enter length of wall 3: '))
wall4 = float(input('enter length of wall 4: '))
wall_height = float(input('enter height of walls: '))
combine_walls1 = wall1 + wall2
combine_walls2 = wall3 + wall4
paint_cost(combine_walls1, combine_walls2, wall_height) # 1 + 2
def paint_cost(combine_walls1, combine_walls2, wall_height): # 2
combined_walls = combine_walls1 + combine_walls2
Square_foot = combined_walls * wall_height
gallon = Square_foot / 300
cost = gallon * 40
print('total: $', format(cost, ' ,.2f')) # 3
main()