【发布时间】:2021-09-22 12:09:46
【问题描述】:
我目前正在为大学做项目,我需要使用谷歌表格和 python 创建一个基本的银行系统。我已成功添加客户数据并检查数据是否正确。但是,我希望了解如何根据客户的电子邮件地址检查特定客户的余额。
| Email Address | Full Name | Password | Balance |
|---|---|---|---|
| brian_smith@outlook.com | brian Smith | Password1234 | 500 |
这是我的代码。
def emailcheck(emailinput):
"""
Email validator function
"""
try:
valid = validate_email(emailinput)
emailinput = valid.email
return emailinput
except EmailNotValidError as e:
print("The email you provided is not valid please try again\n")
def registerEmail():
"""
This fucntion checks the email address is correct
while loop will continue until a valid emai is input
"""
print("Welcome to retro bank As a new customer\n" +
"Please complete the following fileds to sign up for an account\n")
while True:
try:
global email
email = input("Please enter your email address: ")
einput = emailcheck(email)
if einput != email:
raise ValueError(
"Please enter a valid email" +
f" you entered: {email}"
)
else:
regDetails()
return email
except ValueError as e:
print(f"Invalid data: {e}, please try again.\n")
def regDetails():
sheet = SHEET.worksheet("customer-data")
new_cust = []
bonus = 500
while True:
name = input("Please enter your full name: ")
password = input("Please enter your password: ")
if name == "":
print("Name is required")
elif password == "":
print("Password Required")
else:
new_cust.append(email)
new_cust.append(name)
new_cust.append(password)
new_cust.append(bonus)
sheet.append_row(new_cust)
print("WELCOME TO RETRO BANK !" +
" As a new customer you will receive £500 joining bonus")
login()
break
def login():
"""
This fucntion will allow the exisiting user
log into their bank account
"""
global email_ver
global details
global password
global balances
email_ver = SHEET.worksheet("customer-data")
details = email_ver.col_values(1)
password = email_ver.col_values(3)
balances = email_ver.col_values(4)
user = []
while True:
ename = input("Please enter your email address: ")
epass = input("Please enter your password: ")
if ename == "":
print("Name is required")
elif epass == "":
print("Password Required")
else:
break
user.append(ename)
user.append(epass)
found = 0
for i in zip(details, password):
if i == tuple(user):
found = 1
print("Successfully Verified")
mainDash(user)
return found
if found == 0:
print("The username or the password you provided might be wrong.\n")
login()
return found
def mainDash(user):
print(user)
print("WELCOME")
for i in (details):
if i == user:
print()
【问题讨论】:
-
考虑阅读 API 文档。
标签: python google-sheets gspread