题目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: {0}".format(box_count))
print("Number of lollies left over: {0}".format(left_over))
实验结果
题目2
写信小游戏,用户输入一些个人信息,输出一封简单的打招呼信,如下图所示: