我得到一个EOF错误,不知道如何修复我

2024-09-28 22:22:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试编写一个符合这些规则的程序:
你的租约到期了,该搬家了。不幸的是,你有很多东西,你不想花太多时间移动它,因为你宁愿练习你的编程技能。谢天谢地,你有可以帮忙的朋友,尽管这种帮助是有代价的。你的朋友一小时可以搬动20个盒子,但他们需要一个16英寸(直径)的比萨饼。用Python编写一个函数,获取你拥有的盒子数量,并返回你需要购买多少平方英尺的比萨饼。使用函数头:sqFtPizza(numBoxes)

让它把比萨饼的平方英尺作为浮子送回来。你知道吗

这是我的密码

def sqFtPizza(numBoxes):
    a = 3.14159*(8*8)
    c = 1/12**2
    sqft = a * c
    za =numBoxes/20
    area = za * sqft
    print (area)
def question():
    numBoxes= float(int(input("How many boxes do you have?: " )))
    sqFtPizza(numBoxes)
question() 

请帮忙?你知道吗


Tags: 函数程序规则def时间朋友area盒子
1条回答
网友
1楼 · 发布于 2024-09-28 22:22:12

使函数名PEP8兼容

#  - Python 2.x  -
from __future__ import division          # make int/int return float
from math import pi

PIZZA_PER_BOX = pi * (8 / 12)**2 / 20    # one 16" pizza per 20 boxes

def sq_ft_pizza(num_boxes):
    """
    Input:  number of boxes to be moved
    Output: square feet of pizza to feed movers
    """
    return PIZZA_PER_BOX * num_boxes

def main():
    num_boxes = float(raw_input("How many boxes must you move? "))
    print("You need {:0.2f} square feet of pizza!".format(sq_ft_pizza(num_boxes)))

if __name__ == "__main__":
    main()

就像

How many boxes must you move? 120
You need 8.38 square feet of pizza!

相关问题 更多 >