【发布时间】:2011-11-18 08:56:24
【问题描述】:
我一直在尝试制作类似代码的收银机,用户可以在其中输入产品名称、价格和数量。我有四种产品。在完成所有这些添加后,我需要获得 5% 的 GST,然后打印出包括 GST 在内的总金额。这是我到目前为止所能提供的,而且我是 python 新手,这就是为什么我不知道很多错误和其他关键字的原因。我得到和 ut 一切,但是当我相乘时,它说它不能将字符串和整数相乘。我尝试更改变量名称并做了所有其他的事情,但它不会给出总数。
name1 =raw_input('What Item do you have: ')
price1 = float(input('What is the price of your item: '))
quantity1 = float(input('How many are you buying: '))
name2 = raw_input('What Item do you have: ')
price2 = float(input('What is the price of your item: '))
quantity2 = float(input('How many are you buying: '))
name3 = raw_input('What Item do you have: ')
price3 = float(input('What is the price of your item: '))
quantity3 = float(input('How many are you buying: '))
name4= raw_input('What Item do you have: ')
price4 = float(input('What is the price of your item: '))
quantity4 = float(input('How many are you buying: '))
sum_total= (price1 * quantity1), (price2 * quantity2), (price3 * quantity3), (price4 * quantity4),
print(' %.2f ' % quantity1+quantity2+quantity3,' X ', name1+name2+name3,' @ %.2f ' %
price1+ price2+price3,' = %.2f ' % total)
divv = sum_total / 100
percent = divv * 0.05
gst = sum_total + percent
print('The suggested gst is %.2f '% percent )
print('That will be a total of: %.2f '% gst)
【问题讨论】:
-
请告诉我热得到总数,我该如何解决谢谢
-
如果我只是告诉你如何解决它,我将不得不为你编写一个全新的程序,而你将一无所获。您编写这样一个程序的原因有两个:作为家庭作业或出于您自己的学习目的。在这两种情况下,我都不想给你一个完整的解决方案。
-
@Yousuf 你真的应该听从 Björn Pollex 的建议,并可能阅读一个很好的教程和其他介绍性材料。两个很好的可能性是 python 文档和在线书籍“Dive into Python”。
-
我现在肯定会先阅读文档
-
“先阅读文档” -> 这是一个绝妙的主意。这样,您将不会学会解决给定的简单任务,但您将成为真正的程序员!在网上找到的盲目复制粘贴sn-ps和真正有想法、解决问题的区别……
标签: python