Hey group,
I am new on here, and also to Python. I have been setting myself various tasks to try to learn more about this language and have a small query.
I set myself a "Cash Machine" task, and although I am still yet to add multiples of 10, overdraft etc.... I keep getting a negative value as a result which is literally "bugging" me *sticks fork in leg for the sad pun.
Any ideas on where exactly right under my nose I have booboo'd? Even with a positive result, the script outputs a negative value.
Thanks.
I am new on here, and also to Python. I have been setting myself various tasks to try to learn more about this language and have a small query.
I set myself a "Cash Machine" task, and although I am still yet to add multiples of 10, overdraft etc.... I keep getting a negative value as a result which is literally "bugging" me *sticks fork in leg for the sad pun.
Any ideas on where exactly right under my nose I have booboo'd? Even with a positive result, the script outputs a negative value.
Thanks.
Code:
######################################
#!/usr/bin/python -tt
# -*- coding: cp1252 -*-
from random import choice
import sys, math
class BreakLoop:
pin_attempts = "PIN failed to authorise on three attempts"
card_returned = "Card returned to account holder"
class Account_Detail(object):
def __init__(self, name, surname, balance, account, PIN):
self.name = name
self.surname = surname
self.balance = balance
self.account = account
self.PIN = PIN
### Populate database
acc1 = Account_Detail('Jeff', 'Minter', 200.18, 789321, 1234)
acc2 = Account_Detail('Tim', 'Lambesis', 182.63, 147852, 7896)
acc3 = Account_Detail('Matt', 'Heafy', 350.58, 963258, 9874)
### Prep and setup random choice for entering card into machine
account1 = [acc1.name, acc1.surname, acc1.balance, acc1.account, acc1.PIN]
account2 = [acc2.name, acc2.surname, acc2.balance, acc2.account, acc2.PIN]
account3 = [acc3.name, acc3.surname, acc3.balance, acc3.account, acc3.PIN]
rand_acc = [account1, account2, account3]
card_choice = choice(rand_acc)
print card_choice[4]
def ins_card():
count = 0
while count < 3:
print "Your account number is %i" % (card_choice[3])
card_in = input ("Please enter your PIN: ")
if card_in == (card_choice[4]):
print "Hello, %s %s" %(card_choice[0], card_choice[1])
print "Your account balance is £%.2f " % (card_choice[2])
count = 4
elif card_in == (''):
print "No PIN entered"
else:
print "Incorrect PIN"
count = count + 1
if count == 3:
print; print "PIN entry has exceeded three attempts"
sys.exit(BreakLoop.pin_attempts)
def withdraw():
amount = input ("How much would you like to withdraw?: ")
if amount <= card_choice[2]:
#print amount
#print card_choice[2]
tot_bal = amount - card_choice[2]
print; print "Dispensing £%i" % (amount)
print "Your new balance is £%.2f" % (tot_bal)
print "Have a nice day"
else:
funds = "You do not have sufficient funds available"
print; print funds.upper()
sys.exit(BreakLoop.card_returned)
if __name__ == "__main__":
ins_card()
withdraw()
####################################
Comment