我在 Python 2.7.3 中创建了这个程序,我在计算机科学课上做了这个。他把它分成两部分。在第一部分,我们必须创建一个程序来计算五个客户的每月手机账单。用户输入使用的文本数、分钟数和数据。此外,还有超额费用。超过限制的每 GB 数据 10 美元,超过限制每分钟 0.4 美元,超过限制发送的每条文本 0.2 美元。500 是短信的限制量,750 是分钟的限制量,2 GB 是计划的数据量限制。
对于作业的第 2 部分。我必须计算征收的总税款、总费用(每个客户账单加在一起)、征收的政府总费用、超额客户总数等。
现在我想要的只是将客户账单加在一起。正如我之前所说,当您运行该程序时,它会打印 5 个客户的总帐单。我不知道如何将这些单独的总数分配给一个变量,将它们加在一起,然后最终将它们打印为一个大变量。
TotalBill = 0
monthly_charge = 69.99
data_plan = 30
minute = 0
tax = 1.08
govfees = 9.12
Finaltext = 0
Finalminute = 0
Finaldata = 0
Finaltax = 0
TotalCust_ovrtext = 0
TotalCust_ovrminute = 0
TotalCust_ovrdata = 0
TotalCharges = 0
for i in range (1,6):
print "Calculate your cell phone bill for this month"
text = input ("Enter texts sent/received ")
minute = input ("Enter minute's used ")
data = input ("Enter Data used ")
if data > 2:
data = (data-2)*10
TotalCust_ovrdata = TotalCust_ovrdata + 1
elif data <=2:
data = 0
if minute > 750:
minute = (minute-750)*.4
TotalCust_ovrminute = TotalCust_ovrminute + 1
elif minute <=750:
minute = 0
if text > 500:
text = (text-500)*.2
TotalCust_ovrtext = TotalCust_ovrtext + 1
elif text <=500:
text = 0
TotalBill = ((monthly_charge + data_plan + text + minute + data) * (tax)) + govfees
print ("Your Total Bill is... " + str(round(TotalBill,2)))
print "The toatal number of Customer's who went over their minute's usage limit is... " ,TotalCust_ovrminute
print "The total number of Customer's who went over their texting limit is... " ,TotalCust_ovrtext
print "The total number of Customer's who went over their data limit is... " ,TotalCust_ovrdata
一些创建的变量没有在程序中使用。请忽略它们。