The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Problems using 'if'
Discuss Problems using 'if' in the Python Programming forum on Dev Shed. Problems using 'if' Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 1st, 2013, 04:33 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
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
|

January 1st, 2013, 05:33 PM
|
 |
Lord of the Dance
|
|
|
|
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: '))
|

January 1st, 2013, 05:37 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
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.
|

January 2nd, 2013, 02:37 PM
|
 |
Contributing User
|
|
|
|
|
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
|

January 2nd, 2013, 02:40 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 3
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|