我主要是通过在这里阅读开始学习课程的
https://pythonprogramming.net/classes-python-3-basics-tutorial/
我也试图在类之间进行分支,但是出于某种原因
当我进入结果课时
我收到一个未定义费用的错误。
有人可以告诉我我做错了吗?
class calculator():
def money(self):
print("What was the cost?")
cost = input("> ")
diners.amount_of_diners()
class diners():
def amount_of_diners():
print("How many people are with you?")
diners = input("> ")
precent.precent_to_give()
class precent():
def precent_to_give():
print("How much '%' you want to give the waiter? ")
prec = input("> ")
result.the_end()
class result():
def the_end():
print("The total amount of money each of you need have to give is: ",cost * diners)
calc = calculator()
calc.money()
最佳答案
成本是money()的局部变量,而result()无法访问