所以我用python3.3制作了一个pizza程序,它接受用户的输入并打印所需的比萨数量。每个比萨饼都切成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
向上取整。在相关问题 更多 >
编程相关推荐