在python 3.4中用户输入墙信息后如何让我的绘图程序继续运行

时间:2014-10-04 01:56:22

标签: python debugging python-3.x

我正在编写一个油漆程序,该程序应该确定用矩形地板绘制棚屋墙壁的成本。我应该假设棚子没有窗户,油漆成本是每加仑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()

1 个答案:

答案 0 :(得分:0)

  1. paint_cost未被调用。
  2. paint_cost应该收到wall_height
  3. cost中打印paint_cost而不是paint_cost

  4. 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()