#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Problems using 'if'


    Hello, I am having problems using the following code, specifically using if inside 'while r==0:' near the bottom. I have tried to narrow down the problem and have found that it is ignoring if completely but will carry out parts before and after the 'if's.

    If I have written parts strange that is because I am just starting out in Python.

    I included the whole code in case a part early on was relevant to why the problem is occurring.

    Thank you in advance.

    Code:
    import math
    
    m=0
    g=0
    h=0
    i=0
    j=0
    r=0
    y=0
    
    ATitle = 'Mr.'
    BTitle = 'Miss'
    CTitle = 'Mrs'
    DTitle = 'Mr.'
    
    AFirstName = 'Jeremy'
    BFirstName = 'Suzanne'
    CFirstName = 'Vicki'
    DFirstName = 'Jason'
    
    ALastName = 'Clarkson'
    BLastName = 'Perry'
    CLastName = 'Butler-Henderson'
    DLastName = 'Plato'
    
    ABalance = '172.16'
    BBalance = '15.62'
    CBalance = '23.91'
    DBalance = '62.71'
    
    toDeposit1=0
    toWithdraw1=0
    
    APin=708.117722086754
    BPin=632.2929832495903
    CPin=615.4608706760596
    DPin=857.806359267638
    
    def decodePin(APin):
        Step1 = APin*APin
        Step2 = Step1/9001
        Pin = Step2*24
    
    APinResult = decodePin(APin)
    BPinResult = decodePin(BPin)
    CPinResult = decodePin(CPin)
    DPinResult = decodePin(DPin)
    
    def encodePin(APinResult):
        StepLeft1 = APinResult*24
        StepLeft2 = StepLeft1*9001
        StepLeftPin = math.sqrt(StepLeft2)
        
    
    def withdrawal(ABalance,toWithdraw1):
                print("Checking to see if withdrawl is permitted...")
                if ABalance >= toWithdraw1:
                    print('Withdrawal successful!')
                    ABalance = ABalance - toWithdraw1
                    print('Your balance is now: ','',ABalance)
                else:
                    print('Error: Your balance is too low to make the withdrawal.')
    
    def maxWithdrawal(ABalance):
        Part1 = ABalance%10
        Part2 = ABalance-Part1
        print(Part2)
    
    def deposit(ABalance,toDeposit1):
        ABalance = ABalance+toDeposit1
        print('Deposit succesfull. Your balance is now: ','',ABalance)
    
    def fullMenu(ABalance):
        x=0
    
        while x == 0:
    
            menu = "Welcome to Northern Frock\n\
            1. Display balance\n\
            2. Withdraw funds\n\
            3. Deposit funds\n\
            9. Return card\n"
    
            answer = int(input(menu))
    
            if answer == 1:
                print("Your balance is: ","",ABalance)
                print("The maximum available for withdrawal is: ","",maxWithdrawal1(ABalance))
    
            elif answer == 2:
                menu2 ="Would you like to withdraw:\n\
                1. 10\n\
                2. 20\n\
                3. 40\n\
                4. 60\n\
                5. 80\n\
                6. 100\n\
                7. Other amount (must be a multiple of 10)\n\
                8. Return card\n"
                              
                answer2 = int(input(menu2))
    
                if answer2 == 1:
                    toWithdraw1=10
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 2:
                    toWithdraw1=20
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 3:
                    toWithdraw1=40
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 4:
                    toWithdraw1=60
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 5:
                    toWithdraw1=80
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 6:
                    toWithdraw1=100
                    withdrawal(ABalance,toWithdraw1)
                elif answer2 == 7:
                    toWithdraw1 = int(input('Enter a value to be withdrawn (must be a multiple of 10)'))
                    print("Checking to see if withdrawl is permitted...")
                    if toWithdraw1%10 == 0:
                        if toWithdraw1>=ABalance:
                            ABalance = ABalance - 10
                            print('Withdrawal successful!')
                            print('Your balance is now: ','',ABalance)
                        else:
                               print('Error: Your balance is  too low to withdraw that amaount')
                    else:
                        print('Error: You can only withdraw multiples of 10')
                elif answer2 == 8:
                    x=1
            elif answer == 3:
                menu2 ="Would you like to deposit:\n\
                1. 10\n\
                2. 20\n\
                3. 40\n\
                4. 60\n\
                5. 80\n\
                6. 100\n\
                7. Other amount\n\
                8. Return card\n"
                              
                answer2 = int(input(menu2))
    
                if answer2 == 1:
                    toDeposit1 = 10
                    deposit(ABalance,toDeposit1)
                elif answer2 == 2:
                    toDeposit1=20
                    deposit(ABalance,toDeposit1)
                elif answer2 == 3:
                    toDeposit1=40
                    deposit(ABalance,toDeposit1)
                elif answer2 == 4:
                    toDeposit1=60
                    deposit(ABalance,toDeposit1)
                elif answer2 == 5:
                    toDeposit1=80
                    deposit(ABalance,toDeposit1)
                elif answer2 == 6:
                    toDeposit1=100
                    deposit(ABalance,toDesposit1)
                elif answer2 == 7:
                    toDeposit1 = input('Enter the amount to deposit')
                    ABalance = ABalance+toDeposit1
                    print('Deposit succesfull. Your balance is now: ','',ABalance)
                elif answer2 == 8:
                    x=1
            elif answer == 9:
                x=1
    
    def pinVerification(APinResult,ABalance,g):
        if g == 0:
            while y==0:
                pin = input('Please enter your pin: ')
                A = encodePin(pin)
                if A == APinResult:
                    print('Pin accepted!')
                    fullMenu(ABalance)
                    y=0
                else:
                    q=0
                    while q==0:
                        if m==3:
                            print('The card has been locked')
                            g=1
                        else:
                            m=m+1
                            menu9="That is the incorrect pin would you like to:\n\
                            1. Make another attempt at entering the correct pin\n\
                            2. Return card\n"
                            toDo=int(input(menu9))
    
                            if toDo == 1:
                                q=1
                            elif toDo == 2:
                                y=1
        else:
            print('The card has been locked.')
    
    while r==0:
    
        ID = input('Please enter your ID number: ')
        if ID==1057:
            pinVerification(APinResult,ABalance,g)
        elif ID==2736:
            pinVerification(BPinResult,BBalance,h)
        elif ID==4659:
            pinVerification(CPinResult,CBalance,i)
        elif ID==5691:
            pinVerification(DPinResult,DBalance,j)
        elif ID==99999:
            r=1
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,581
    Rep Power
    1906
    the input return text to the ID, but you are checking for numbers.
    You will have to either check for text value:
    Code:
        if ID=="1057":
            pinVerification(APinResult,ABalance,g)
    or convert the input to number:
    Code:
       ID = int(input('Please enter your ID number: '))
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Thank you very much. I originally started out using int, but presumed it was just to make sure the number is not decimal.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    608
    Rep Power
    65
    Your code is crying out for a Record Class, a dictionary (key=ID) or a named tuple. Then you can use loops for most chores.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by Dietrich
    Your code is crying out for a Record Class, a dictionary (key=ID) or a named tuple. Then you can use loops for most chores.
    As I said I'm just starting and its quite a mess I know as I've been trying to debug it for ages. But I'll keep that noted.

IMN logo majestic logo threadwatch logo seochat tools logo