第一次使用Python,我通常的“编码”是在excel中完成的,所以我可能做错了很多。但一次只能做一件事。使用程序让用户输入零件号、数量、成本、售价和工时。我目前有它吐出利润,利润,销售价格在20%的利润率,和最终销售价格
我希望它能够在一个循环中收集所有数据,并在另一个循环中打印所有数据。目前它在同一个循环中收集和打印,因为我一直在写变量。目标是让每个输入循环增加计数器,然后生成一个输出循环,减少计数器,直到达到0
通过组合变量名和计数器来生成变量,我没有成功。我希望这样做是为了有partNum1、partNum2等等,而不是每次都写partNum。到目前为止,partNum+inputCount或其使用str、float和int的变体对我不起作用
这是代码,一些评论是提醒,一些只是代码,没有工作,但表明“逻辑”我一直在尝试
#program to help with quoting and calculating margin
#declare a few global variables before the program gets angry about calling them
inputCount = 0
totalCost = 0
totalPrice = 0
totalProfit = 0
totalMargin = 0
moreParts = 'y'
#input section
while moreParts != 'n':
#while moreParts != 'n' or 'N' or 'No' or 'no' or 'NO':
#increase counter
inputCount += 1
#inputCount = inputCount + 1
#get part number
print ('Part number: ')
partNum = input()
#partNum + inputCount = str(currentPart)
#str(partNum) + str(inputCount) = input()
#get part quantity
print ('Quantity: ')
partQty = input()
#get part cost
print ('Cost: ')
partCost = input()
partCost = float(partCost) * int(partQty)
#get part sale price
print ('Sale price: ')
partPrice = input()
partPrice = float(partPrice) * int(partQty)
#calculate profit & margin
partProfit = float(partPrice) - float(partCost)
partMargin = float(partProfit) / float(partPrice) * 100
#increase totals for each part entered
totalCost += float(partCost)
totalPrice += float(partPrice)
#totalCost = float(totalCost) + float(partCost)
#totalPrice = float(totalPrice) + float(partPrice)
totalProfit = float(totalPrice) - float(totalCost)
totalMargin = float(totalProfit) / float(totalPrice) * 100
twentyPoints = float(totalCost) * 1.25
#Summary of the data entered
print ()
print ('* * * Report Section * * *')
print ('PN: ' + str(partNum))
print ('Qty: ' + str(partQty))
print ('Cost: ' + str(partCost))
print ('Sale Price: ' + str(partPrice))
print ('Profit: ' + str(partProfit))
print ('Margin: ' + str(partMargin) + '%')
print ()
print ('Add another part? (y/n) ')
moreParts = input(str())
#end of while loop
#calculating labour section
print ()
print ('Hours of labour: ')
hours = input()
#uncomment these lines if changing shop rate from $145/hour
#print ('Hourly labour rate: ')
#rate = input()
rate = 145
labour = float(hours) * float(rate)
totalFinal = float(labour) + float(totalPrice)
#Final summary of report
print ()
print (' * * * SUMMARY * * *')
print ('Different part numbers: ' + str(inputCount))
#while inputCount <= 0:
#print ((str(partQty) + int(inputCount)) + ' of ' (str(partNum) + int(inputCount))
#int(inputCount) - 1
print ('Total cost of parts: $' + str(totalCost))
print ('Profit: $' + str(totalProfit))
print ('Margin: ' + str(totalMargin) + '%')
print ('Sale price of parts: $' + str(totalPrice))
print ('Sale price at 20% margin: $' +str(twentyPoints))
print ('Total labour charge: ' + str(labour))
print ()
print ('Before tax parts & labour price: $' +str(totalFinal))
print ()
input("Press enter to exit")
你想要的有点让人困惑,所以请耐心听我解释你想要做的事情:
鉴于这一系列指示,我将按照以下步骤进行:
相关问题 更多 >
编程相关推荐