如何修复“ NameError:未定义名称'createAcct'”

时间:2019-07-24 01:10:27

标签: python

Traceback (most recent call last):
  File "bankAccount.py", line 5, in <module>
    class bankAccount:
  File "bankAccount.py", line 38, in bankAccount
    action = input("What would you like to do today? (createAcct, depCheck, depSaving, depRetirement, etc)")
  File "<string>", line 1, in <module>
NameError: name 'createAcct' is not defined
Alexanders-MacBook-Pro:Python Projects alexanderhaislip$ 

试图放入__Main__,但仍然无法正常工作。

代码:

import time as t
import sys


class bankAccount:
    def __init__(self, checking, savings, retirement, name):
        #instance variables(variables that make up your class bankAccount)
        self.checking = checking
        self.saving = savings
        self.retirement = retirement
        self.name = "name"

    def getCheckingBalance(self):
        return self.checking

    def getSavingsBalance(self):
        return self.saving

    def getRetirementBalance(self):
        return self.retirement

    def getName(self):
        return self.name

    def depCheckingBalance(self, amount):
        self.checking += amount

    def depSavingBalance(self, amount):
        self.saving += amount

    def depRetirementBalance(self, amount):
        self.retirement += amount

    def setName(self, newName):
        self.name = newName


    action = input("What would you like to do today? (createAcct, depCheck, depSaving, depRetirement, etc)")

    if action == "createAcct":
            initialChecking = input("Enter starting checking balance: ")
            initialSavings = input("Enter starting savings balance: ")
            initialRetirement = input("Enter starting retirement balance: ")
            initialName = input("Enter the new account name: ")
            action = bankAccount(initialChecking,initialSavings,initialRetirement,initialName)

    if action == "depCheck":
        depCheckingBalance = input("Enter the check amount: ")
        depCheckingBalance + depCheckingBalance(self,depCheckingBalance)
        action = bankAccount(initialChecking,initialSavings,initialRetirement,initialName)

0 个答案:

没有答案
相关问题