Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2013, 04:33 PM
LibeRatioNZzXx LibeRatioNZzXx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 LibeRatioNZzXx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 25 sec
Reputation 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

Reply With Quote
  #2  
Old January 1st, 2013, 05:33 PM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,161 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 13 h 43 m 52 sec
Reputation Power: 1736
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: '))

Reply With Quote
  #3  
Old January 1st, 2013, 05:37 PM
LibeRatioNZzXx LibeRatioNZzXx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 LibeRatioNZzXx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 25 sec
Reputation 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.

Reply With Quote
  #4  
Old January 2nd, 2013, 02:37 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 499 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 3 h 19 m 2 sec
Reputation Power: 63
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

Reply With Quote
  #5  
Old January 2nd, 2013, 02:40 PM
LibeRatioNZzXx LibeRatioNZzXx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 LibeRatioNZzXx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 25 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Problems using 'if'

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap