程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Using pandas to realize a simple login system for users with different identities

編輯:Python

  This project comes from the College of measurement and control technology and communication engineering of Harbin University of technology Python Big homework .

Open source after completion for everyone to learn and progress .

form form_man.xlsx The initial style is as follows ( Act as a database ):

              Login account                             password
import pandas as pd
def selector():
print("-------****-------")
print("1, Agency Administrator ")
print("2, Customer ")
print("3, tourists ")
print("-------****-------")
identity_number = input(" Please choose your identity ( Enter the corresponding number !!!)?")
return identity_number
# This function implements the login function
def Login(identity_number):
# ID_man = pd.DataFrame(columns=(' Login account ', ' password '))
outputpath_man = './form_man.xlsx'
outputpath_cli = './form_cli.xlsx'
ID_man = pd.read_excel(outputpath_man)
ID_cli = pd.read_excel(outputpath_cli)
# ID_cli = pd.DataFrame(columns=(' Login account ', ' password '))
# print(ID_man)
if identity_number == '1':
flag = 0
print(" Please enter your login account and password !")
id_man = input(" Login account :")
pass_man = input(" password :")
dic_man = {' Login account ': [id_man], ' password ': [pass_man]} # Convert nominal variables , Otherwise, the report will be wrong
ID_man1 = pd.DataFrame(dic_man)
# print(num)
# print(list(ID_man[' Login account ']))
# print(ID_man[' Login account ']['A02200181'])
if id_man not in list(ID_man[' Login account ']):
ID_man = pd.concat([ID_man, ID_man1], axis=0)
# ID_man.append([], ignore_index=True)
ID_man.to_excel(outputpath_man, index=False, header=True)
print(" Login successful !")
flag = 1
Printf(flag)
RootMan()
# print(ID_man)
# df.loc[df['gender']=='m','name'] # selection gender The column is m,name Columns of data
# df.loc[df['gender']=='M',['name','age']] # selection gender The column is m,name and age Columns of data
elif str(ID_man.loc[ID_man[' Login account '] == id_man, ' password '][0]) != pass_man:
print(" Wrong password , Please re select and enter !")
# selector()
else:
print(" Login successful !")
flag = 1
Printf(flag)
RootMan()
elif identity_number == '2':
# ID_cli1=pd.DataFrame(columns=(' Login account ',' password '))
judge = input(" Whether to log in for the first time (yes or no):")
if judge == "yes":
print(" Please enter your account and password to register ")
id_cli = input(" Login account :")
pass_cli = input(" password :")
dic_cli = {' Login account ': [id_cli], ' password ': [pass_cli]}
ID_cli1 = pd.DataFrame(dic_cli)
ID_cli = pd.concat([ID_cli, ID_cli1], axis=0, ignore_index=True)
ID_cli.to_excel(outputpath_cli, index=False, header=True)
print(" Login successful !")
flag = 1
Printf(flag)
RootCli()
elif judge == 'no':
print(" Please enter your account and password ")
id_cli = input(" Login account :")
pass_cli = input(" password :")
if id_cli not in list(ID_cli[' Login account ']):
print(" Your relevant information has not been found !")
print(" Please sign up and log in !")
elif str(ID_cli.loc[ID_cli[' Login account '] == id_cli, ' password '][0]) != pass_cli:
print(" Login failed ! Wrong password ")
else:
print(" Landing successful !")
flag = 1
Printf(flag)
RootCli()
elif identity_number == '3':
print(" Please enter your account and password to log in \n"
" Please fill in the login account :youke\n"
" Please fill in the password :123456")
id_tou = input(" Login account :")
pass_tou = input(" password :")
if id_tou == 'youke' and pass_tou == '123456':
print(" Login successful !")
flag = 1
Printf(flag)
RootTou()
else:
print(" Login failed !")
print(" Please check whether the account or password is filled in correctly !")
# return flag
def Printf(flag):
if flag == 1:
print(" Welcome to tal children education group !")
print("----------------******----------------")
print(" Corporate name : Tal children education group ")
# print("\033[1;30m Good future \033[0m")
# print("\033[1;31m Good future \033[0m")
# print("\033[1;32m Good future \033[0m")
print(" company logo:"
"\033[1;33m Good future \033[0m")
# print("\033[1;34m Good future \033[0m")
# print("\033[1;35m Good future \033[0m")
# print("\033[1;36m Good future \033[0m")
# print("\033[1;37m Good future \033[0m")
print(" The company address : Haike Road, Wenjiang District, Chengdu City, Sichuan Province 234 Number ")
print("----------------******----------------")
elif flag == 0:
print(" Please login successfully before accessing !")
def RootMan():
print(" As Administrator , You have the right to adjust accordingly \n"
"1, Set preferential policies for new and old customers .\n"
"2, Offer discounts to users who buy courses in large quantities .\n")
rootman_number = input(" Please enter the corresponding number for management :")
if rootman_number == '1':
print(' All regular customers call 9 fold !')
print(' There is no discount for new customers , After successfully becoming a registered member, you will enjoy the general treatment of regular customers !')
elif rootman_number == '2':
print(" For the purchase of courses, the price is 30000 For users above RMB yuan, please call 8 Folding !")
def RootCli():
sle_form = []
price = 0
while True:
print(" As a customer , You have the following choices ! Please input the corresponding number to complete the corresponding function !\n"
" Input T You can exit this function !")
print("1, Browse course information ")
print("2, Shop courses ")
print("3, View order information ")
print("4, Complete the payment function ")
rootcli_number = input(" Please enter your choice :")
if rootcli_number == 'T':
break
elif rootcli_number == '1':
print(" Swimming class information :\n"
" Class size :20-30 people \n"
" Hardware facilities : Two super large constant temperature natatoriums \n"
" faculty : All the teachers are doctors majoring in swimming from Beijing Sport University \n"
" The tuition fees :8000 A month \n")
print(" Calligraphy class related information :\n"
" Class size :40-50 people \n"
" Hardware facilities : Advanced dog brush , Zhejiang gold paper \n"
" faculty : All the teachers are doctors majoring in calligraphy from Peking University \n"
" The tuition fees :6000 A month \n")
print(" Information about dance classes :\n"
" Class size :10-15 people \n"
" Hardware facilities : Chengdu Central Committee CBD500 Square meters of large dance venues \n"
" faculty : The teachers are all from the Central University for nationalities , Doctor of dance major of Beijing Normal University \n"
" The tuition fees :10000 A month \n")
elif rootcli_number == '2':
print("------------ Press T Quit course selection ------------")
while True:
sle = input(" Please enter the relevant course name to purchase :")
if sle != 'T':
sle_form.append(sle)
sle_form = sle_form.copy()
if sle == 'T':
print(" End of course selection , Please pay !")
break
elif rootcli_number == '3':
print(" Your order information is as follows :")
sle_count = pd.DataFrame(sle_form).value_counts()
print(sle_count)
elif rootcli_number == '4':
for i in sle_form:
if i == ' Swimming class ':
price += 8000
elif i == ' Calligraphy class ':
price += 6000
elif i == ' dance lesson ':
price += 10000
print(" You should pay {0} element !".format(price))
price_cli = int(input(" Please pay :"))
if price_cli == price:
print(" Payment succeeded !")
else:
print(" Please pay again !")
def RootTou():
print(" As a tourist , You can browse the following information :")
print(" Swimming class information :\n"
" Class size :20-30 people \n"
# " Hardware facilities : Two super large constant temperature natatoriums \n"
# " faculty : The teachers are all doctors majoring in swimming at Tsinghua University \n"
" The tuition fees :8000 A month \n")
print(" Calligraphy class related information :\n"
" Class size :40-50 people \n"
# " Hardware facilities : Advanced dog brush , Zhejiang gold paper \n"
# " faculty : All the teachers are doctors majoring in calligraphy from Peking University \n"
" The tuition fees :6000 A month \n")
print(" Information about dance classes :\n"
" Class size :10-15 people \n"
# " Hardware facilities : Chengdu Central Committee CBD500 Square meters of large dance venues \n"
# " faculty : The teachers are all from the Central University for nationalities , Doctor of dance major of Beijing Normal University \n"
" The tuition fees :10000 A month \n")
def main():
identity_number = selector()
Login(identity_number)
# Printf(flag)
# RootCli()
main()

The code I have completed seems rough in terms of administrator permissions , You can further modify , To be more perfect .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved