如何制作一个程序,询问用户购买了多少商品,然后询问每件商品的价格 . 我有这个:
a = input("Enter the number of different items you are purchasing")
for i in range(1,a+1):
b = input("Enter the price of item number")
c = input("Enter the quantity of this item")
但是,我不知道如何使输入语句说“输入数字价格1”而第二个循环“输入项目2的价格”
1 回答
我将给出它的第一部分 - input()内置函数允许您在命令行中从用户请求和存储字符串 .
这将提示用户输入,打印在插入符号之前传递给input()的字符串:
当用户点击enter时,从input()返回一个字符串,然后可以将其存储在变量中:
那么,你需要做的是四个:
确定价格和数量的数据类型,以及如何确保用户数据符合这些参数 .
弄清楚如何将任何项目的数量和价格合并为一个总价格 .
弄清楚如何在税收上加税 .
输出该值 .
这是Python中input and output的教程 .