【发布时间】:2017-07-30 15:35:37
【问题描述】:
你好,我有一个 python 代码不断给我一个错误,在我继续之前有人可以看看它。这是为了让我的 python 类计算手机账单金额。我现在有这个但它没有返回值
经济计划包括 30 美元的无限语音和文本、10 美元的 1 GB 数据和每 GB 6 美元。
正常计划包括 30 美元的无限制语音和文本、5 GB 数据(30 美元)和每 GB 4 美元。
class cellphone:
cost = 30
due = 0
amountGB = 0
Total = 0
def econPlan (self, gB, gbOver):
self.cost = 30
self.gB = 1
self.gbOver = 6
self.due = 0
while amountGB >= self.gB:
int(amountGB - self.gB)* self.gbOver
return self.due
while cPlan == Econ and amountGB >= self.gB:
print ("$",self.due)
def normPlan (self, gB, gbOver):
self.cost = 30
self.gB = 5
self.gbOver = 4
while amountGB >= self.gB:
int(amountGB - self.gB)* self.gbOver
return self.due
while cPlan == Norm and amountGB >= self.gB:
print ("$",self.due)
print (" Which Plan do you have: econ or norm?")
print (" Econ is $30 unlimited voice and text, 1 GB data for $10, and $6 for every GB over.")
print (" Norm is $30 unlimited voice and text, 5 GB data for $30, and $4 for every GB over.")
econ = cellphone.econPlan
norm = cellphone.normPlan
cellphone.cPlan = input ("So which plan do you have? >>")
if cellphone.cPlan == econ:
print ("you have the Economy plan")
elif cellphone.cPlan == norm:
print ("you have the Normal plan")
cellphone.amountGB = input ("how many GB did you used >>")
if cellphone.cPlan == "Econ":
print (cellphone.due)
【问题讨论】:
-
发布错误...
-
错误是什么?
-
self在哪里? -
是自己需要的
-
如果类方法中的块没有适当的缩进。
标签: python python-3.x