PYTHON 如何让披萨程序四舍五入为完整的披萨

How to get a pizza program to round to a full pizza In PYTHON

所以我在 Python 3.3 中制作了一个披萨程序,它接受用户的输入并打印所需的披萨数量。每个披萨都被切成 8 片。所以它是这样工作的:你输入参加聚会的人数,以及每个人平均要吃多少块。然后计算机会告诉您需要订购多少比萨饼。我的问题是,假设有 10 个人来参加聚会,他们平均每人会吃 2 块。电脑给了我 2.5,我需要找到一种方法让它四舍五入到最接近的整数。明白了吗?到目前为止,这是我的代码

 eaters = input("How many people are attending the party?")

 pieces = input("How many pieces will everyone eat on average?")

 pizzas = float(eaters) * float(pieces)
 orders_needed = pizzas/8
 print(orders_needed)

关于如何做到这一点有什么想法吗?

math.ceil 四舍五入。

import math

eaters = input("How many people are attending the party?")

pieces = input("How many pieces will everyone eat on average?")

pizzas = float(eaters) * float(pieces)
orders_needed = math.ceil(pizzas/8)
print(orders_needed)