- import os
- enableCLS = False
- def screen_clear():
- if enableCLS:
- print("Screen_clear is ON ! ")
- if os.name == 'posix':
- _ = os.system('clear')
- else:
- _ = os.system('cls')
- else:
- print("screen clear is off !")
- def ClearScreenSetting():
- global enableCLS
- ch = input("\nDo you want to enable \"Clear screen\"?\n\Press Y for yes , any other keys for NO : ")
- if ch == 'Y' or ch == 'y':
- enableCLS = True
- else:
- enableCLS = False
- #log out function
- def logout():
- lg = input("Do you sure want to log out ?\n[Enter y for yes] [Other key to cancel] : ")
- if lg == 'y' or lg == 'Y':
- main()
- else :
- print("Log out sucessfully!")
- mainmenu_function()
- #function for main menu
- def mainmenu_function():
- exitProgram = False
- while exitProgram == False :
- ch = mainmenu()
- if ch == '1':
- history()
- elif ch == '2':
- logout()
- #def history():
- #after login
- def mainmenu():
- screen_clear()
- print(" ===========================================")
- print(" ===========================================")
- print(" = Welcome back! =")
- print(" =-----------------------------------------=")
- print(" = 1.History purchase =")
- print(" = 2. log out =")
- print(" ===========================================")
- print(" ===========================================")
- ch = input("[Enter according your needs !]: ")
- return ch
- #log in function
- def login():
- success = False
- db = open("user_loggin.txt","r")
- Username = input("Enter your username: ")
- Password = input("Enter your password: ")
- if not len(Username or Password)<1:
- d = []
- f = []
- for i in db:
- a,b = i.split(",")
- b = b.strip()
- d.append(a)
- f.append(b)
- data = dict(zip(d, f))
- try:
- if data[Username]:
- try:
- if Password == data[Username]:
- mainmenu()
- else:
- print("Password or Username incorrect")
- except:
- print("Incorrect password of username")
- else:
- print("username doesn't exist")
- except:
- print("Login error")
- #register and add into the txt file
- def register():
- success = False
- db = open("user_loggin.txt","r")
- Username = input("Create your username: ")
- Password = input("Create your password: ")
- Password1 = input("Confirm your password: ")
- d=[]
- f=[]
- for i in db:
- a,b = i.split(",")
- b = b.strip()
- d.append(a)
- f.append(b)
- data = dict(zip(d,f))
- #print(data)
- if Password != Password1:
- print("Passwords don't match, restart")
- register()
- else:
- if len(Password)<=6:
- print("Password too short, restart")
- register()
- elif Username in d:
- print("Username exists!")
- register()
- else:
- db = open("user_loggin.txt", "a")
- db.write(Username+","+Password+"\n")
- print("Successfully Register!")
- return homepage()
- #home page
- def homepage():
- screen_clear()
- print(" _____________________________________________")
- print(" | Welcome to Bus station ticket ! |")
- print(" | Enter [x] to enable screen clear mode |")
- print(" | Enter [1] to log in into existed account |")
- print(" | Enter [2] to register new account |")
- print(" | Enter [3] to exit from the programme |")
- print(" ---------------------------------------------")
- choice = input("PLease Enter according to your needs :")
- return choice
- #function for home page
- def main():
- global name
- print("This plastform is", os.name)
- exitProgram = False
- while exitProgram == False :
- choice = homepage()
- if choice == 'x' or choice == 'X':
- ClearScreenSetting()
- elif choice == '1':
- login()
- elif choice == '2':
- register()
- elif choice =='3' :
- print("Thank you for using our website !")
- exitProgram = True
- main()
[text] module 1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: