mercredi 27 juillet 2016

BankAccount customer python [duplicate]

This question already has an answer here:

So today I have an assignment that requires me to construct a bank account class. I have everything in order for my output to match the expected output.

My Output:

Alin,Smith (SSN:111-11-1111) account number: 5040470401, balance: $20000
Alin,Smith (SSN:111-11-1111) account number: 5040470401, balance: $15000
Alin,Smith (SSN:111-11-1111) account number: 5040470401, balance: $15100.0
Mary,Lee (SSN:222-22-2222) account number: 5040470401, balance: $10000
Mary,Lee (SSN:222-22-2222) Insufficient Funds to withdraw: $15000
Mary,Lee (SSN:222-22-2222) account number: 5040470401, balance: $10000
Mary,Lee (SSN:222-22-2222) account number: 5040470401, balance: $10500.0

However as you can see, even though Mary and Alin are different customers, they generate the same account number.

My question today is how can I give a different random 10-digit account number for each customer object created in my Bank Account class.

right now I have my Customer class

class Customer:
def __init__(self,firstName, lastName, social):
    self.firstName = firstName 
    self.lastName = lastName 
    self.social = social 

def setfirstName(self,firstName):
    self.firstName = firstName

def setlastName(self,lastName):
    self.lastName = lastName

def __str__(self):
    self.name = "{},{} (SSN:{})".format(self.firstName, self.lastName,self.social)
    return self.name 

and then my BankAccount class (only including random number parts):

class BankAccount(Customer):
from random import randint
n = 10
range_start = 10**(n-1)
range_end = (10**n)-1
accountNumber = randint(range_start, range_end)

def __init__(self,customer,balance = 0):
    self.customer = customer
    self.balance = balance 

def setCustomer(self,customer,accountNumber):
    self.customer = customer
    self.accountNumber = accountNumber 

def getCustomer(self,customer,accountNumber):
    return self.customer, self.accountNumber

 def __str__(self):
    customer = "{} account number: {}, balance: ${}".format(self.customer,self.accountNumber,self.balance)
    return customer 

I figured that for every account object I made, a new random number would be generated but that does not seem to be the case.

Any ideas?




Aucun commentaire:

Enregistrer un commentaire