Python Forum
Getting the error like function not defined .. suggest correct code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting the error like function not defined .. suggest correct code
#1
class ABC:
    def __init__(self,name,accno):
        self.name=name
        self.accno=accno
   
    def main(self):
        print("Welcome to ABC bank , we care for you")
        print("Exciting offers , Loans , Gold schemes and Interest Rates awaits for you")
        trans='y'
        while trans=='y':
            t=input("deposit r withdraw?: ")
            
            if t=='w':
                withdraw()
            if t=='d':
                deposit()
            else:
                print("wrong selection try again")
            trans=input("Any other transaction?")
    def deposit(self):
        balance=0.0
        amount=int(input("enter the amount to deposit"))
        balance+=amount
        print('the balance is',balance)
    def withdraw(self):
        balance=0.0
        amount=int(input("enter the amount to deposit"))
        balance-=amount
        print("the balance is",balance)
c1=ABC("RAGHAVA",1000123)
c1.main()
Reply
#2
I get prompted with input when I run your code, no error. Generally, you should provide complete instructions (e.g. input to reproduce) and not expect us to figure it out for you.

More than that, I suggest you simplify your code. Don't require us to input anything to your code unless it's absolutely required. Hard-code the relevant value(s) instead.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 515 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,165 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Badly defined python code? Ken76 2 571 May-25-2023, 11:05 PM
Last Post: DigiGod
  Getting NameError for a function that is defined JonWayn 2 1,056 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,776 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  How to print the output of a defined function bshoushtarian 4 1,237 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  User-defined function to reset variables? Mark17 3 1,590 May-25-2022, 07:22 PM
Last Post: Gribouillis
  Correct the algorithm of image filter code saoko 6 1,922 May-08-2022, 05:06 PM
Last Post: saoko
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,044 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  The formula in the function is not giving the correct value quest 1 1,217 Mar-30-2022, 03:20 AM
Last Post: quest

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020