【发布时间】:2020-04-07 06:51:33
【问题描述】:
我从事的银行项目的最后一部分是存款/取款功能。我已经让大部分其他位工作(清理代码之外)米挣扎于: 这是我的桌子:
sqlite_file = 'banking2_db.sqlite'
table_1 = 'Bartertown'
table_2 = 'PINs'
id_column = 'Card_Numbers'
column_1 = 'Character_PINs'
column_2 = 'Balances'
column_3 = 'Card_Numbers'
column_4 = 'Characters'
类登录提示: def 登录(自我): 而真: 打印(菜单[1]) self.Card_number=str(输入('>> ')) 打印(菜单[2])
while True:
try:
self.Character_PINs = getpass.getpass('>> ')
self.one_row = c.execute('SELECT * FROM {tn} WHERE {cn}=? and {cnn}=?'.\
format(tn=table_1, cn=column_1, cnn=column_3), (self.Character_PINs, self.Card_number,))
for row in self.one_row.fetchone():
print('Welcome: ', row)
input('Press any key to continue... ')
return
except:
print('PIN incorrect; try again')
break
#MINOR ISSUE, ONLY QUERIES CHAR COLUMN
def loginMenu(self):
while True:
print(menu[5])
print("\n1 - Deposit funds")
print("2 - Withdraw funds")
print("3 - Check balance")
print("4 - Reset Pin")
print("5 - Exit")
while True:
try:
choice = int(input("Please enter a number: "))
except ValueError:
print("Please choose a valid entry")
if choice >= 1 and choice <=5:
choice == 1:
amount = input("\nPlease enter the deposit amount: ")
if amount != '' and amount.isdigit():
int(amount)
balance = c.execute('UPDATE {tn} SET {cn} = Balances +:amount WHERE Card_Numbers =:self.Card_number' .\
format(tn=table_1, cn=column_2,))
new_bal = balance + (int(amount))
print('${} has been deposited to account {} and the new balance is ${}'.\
format(amount, self.Card_number, balance + (int(amount))))
for row in self.Balances.fetchone():
print('Your new balance is: ', new_bal)
return self.loginMenu()
基本上,我试图确保程序只能在指定 PIN 和卡号的情况下提取余额。它选择了天平(这部分正在工作,它是菜单中的另一个选项)但是,更新功能对我来说仍然是一个谜。我了解如何在意外情况下更新整个列...以及如何将余额字段中显示的值更改为用户提交的值,即:用户选择存入 100 个上限,然后他们的余额变为 100 个上限.我要更新的列称为余额,Card_Numbers 是包含用户“信用卡”的列,金额是用户刚刚输入的值。 感谢您的帮助。
编辑:添加表格和数据的初始输入。
【问题讨论】: