何時間もしても、データに名前とパスワードのユーザー入力が存在するかどうかを確認する方法がまだわかりません。たとえば、私がPlease input customer name:
と尋ねると、Please input customer password:
よりも尋ねるよりもSam
が入力され、入力はjanos
です。customer_menu()
関数を呼びたいと思っています。おかげユーザーがデータベースリストに存在するかどうかを確認する方法
customers_list = []
class BankSystem(object):
def __init__(self):
self.customers_list = []
self.load_bank_data()
def load_bank_data(self):
customer_1 = Customer("Sam", "janos", ["14", "Wilcot Street", "Bath", "B5 5RT"])
account_no = 1234
account_1 = Account(5000.00, account_no)
customer_1.open_account(account_1)
self.customers_list.append(customer_1)
def customer_login(self, name, password):
if name in customers_list and password in customers_list:
self.name = name
self.password = password
self.customer_menu()
else:
print("sorry %s, it doesn't look like you are a customer"%name)
exit()
def main_menu(self):
print ("1) Customer login")
print (" ")
option = int(input ("Choose your option: "))
return option
def run_main_option(self):
loop = 1
while loop == 1:
choice = self.main_menu()
if choice == 1:
name = input ("\nPlease input customer name: ")
password = input ("\nPlease input customer password: ")
msg = self.customer_login(name, password)
print(msg)
person.py
class Person(object):
def __init__(self, name, password, address = [None, None, None, None]):
self.name = name
self.password = password
self.address = address
def get_address(self):
return self.address
def update_name(self, name):
self.name = name
def get_name(self):
return self.name
def print_details(self):
print("Name %s:" %self.name)
print("Address: %s" %self.address[0])
print(" %s" %self.address[1])
print(" %s" %self.address[2])
print(" %s" %self.address[3])
print(" ")
def check_password(self, password):
if self.password == password:
return True
return False
def profile_settings_menu(self):
#print the options you have
print (" ")
print ("Your Profile Settings Options Are:")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("1) Update name")
print ("2) Print details")
print ("3) Back")
print (" ")
option = int(input ("Choose your option: "))
return option
def run_profile_options(self):
loop = 1
while loop == 1:
choice = self.profile_settings_menu()
if choice == 1:
name=input("\n Please enter new name\n: ")
self.update_name(name)
elif choice == 2:
self.print_details()
elif choice == 3:
loop = 0
customer.py
from person import Person
class Customer(Person):
def __init__(self, name, password, address = [None, None, None, None]):
super().__init__(name, password, address)
def open_account(self, account):
self.account = account
def get_account(self):
return self.account
def print_details(self):
super().print_details()
bal = self.account.get_balance()
print('Account balance: %.2f' %bal)
print(" ")
あなたはCustomerクラスのコードを追加することはできますか? –
customers_listを辞書にすることは理にかなっていて、キーは顧客の名前であり、値はCustomerオブジェクトです。次に、customer_loginで、名前がcustomer_listにあるかどうかを確認し、パスワードが正しいかどうかを確認できます。また、 'customers_list'は常にクラスメソッドの中で' self.customers_list'でなければならないことを忘れないでください。 –
答えをcustomer.pyとperson.py –