文章目录
- 题目1
-
- 代码
- 实验结果
- 题目2
-
- 代码
- 实验结果
- 题目3
-
- 代码
- 实验结果
- 题目4
-
- 代码
- 实验结果
- 题目5
-
- 代码
- 实验结果
- 题目总结
题目1
打包糖果小游戏,用户输入糖果品牌与个数,还有一个盒子里面可以装多少个糖果,输出一些打印信息,如下图所示:
代码
print("Packaging lollies into boxes")
# ask user for lollies details
brand = input("Enter the lollies brand: ")
user_input = input("Enter number of lollies: ")
count = int(user_input)
user_input = input("How many lollies in 1 box? ")
per_box = int(user_input)
# calculate box needed
box_count = count // per_box
# calculate left over lollies
left_over = count - box_count * per_box
# display result
print()
print("{0} lollies packaging calculation".format(brand))
print("Number of lollies: {0}".format(count))
print("Number of lollies per box: {0}".format(per_box))
print("Number of boxes needed