[text] module 1

Viewer

copydownloadembedprintName: module 1
  1. import os 
  2. enableCLS = False
  3. def screen_clear():
  4.     if enableCLS:
  5.         print("Screen_clear is ON ! ")
  6.         if os.name == 'posix':
  7.             _ = os.system('clear')
  8.         else:
  9.             _ = os.system('cls')
  10.     else:
  11.         print("screen clear is off !")
  12.         
  13. def ClearScreenSetting():
  14.     global enableCLS
  15.     ch = input("\nDo you want to enable \"Clear screen\"?\n\Press Y for yes , any other keys for NO : ")
  16.     if ch == 'Y' or ch == 'y':
  17.         enableCLS = True
  18.     else:
  19.         enableCLS = False
  20.         
  21. #log out function
  22. def logout():
  23.     lg =  input("Do you sure want to log out ?\n[Enter y for yes] [Other key to cancel] : ")
  24.     if lg == 'y' or lg == 'Y':
  25.         main()
  26.     else :
  27.         print("Log out sucessfully!")
  28.         mainmenu_function()
  29.         
  30. #function for main menu
  31. def mainmenu_function(): 
  32.     exitProgram = False
  33.     while exitProgram == False :
  34.         ch = mainmenu()
  35.         if ch == '1':
  36.             history()
  37.         elif ch == '2':
  38.             logout()
  39.         
  40. #def history():
  41.  
  42. #after login 
  43. def mainmenu():
  44.     screen_clear()
  45.     print(" ===========================================")
  46.     print(" ===========================================")
  47.     print(" =  Welcome back!                          =")
  48.     print(" =-----------------------------------------=")
  49.     print(" =   1.History purchase                    =")
  50.     print(" =   2. log out                            =")
  51.     print(" ===========================================")
  52.     print(" ===========================================")
  53.     ch = input("[Enter according your needs !]: ")
  54.     return ch
  55.  
  56. #log in function
  57. def login():
  58.     success = False
  59.     db = open("user_loggin.txt","r")
  60.     Username = input("Enter your username: ")
  61.     Password = input("Enter your password: ")
  62.     
  63.     if not len(Username or Password)<1:
  64.         d = []
  65.         f = []
  66.         for i in db:
  67.             a,b = i.split(",")
  68.             b = b.strip()
  69.             d.append(a)
  70.             f.append(b)
  71.         data = dict(zip(d, f))
  72.         
  73.         try:
  74.             if data[Username]:
  75.                 try:
  76.                     if Password == data[Username]:
  77.                         mainmenu()
  78.                     else:
  79.                         print("Password or Username incorrect")
  80.                 except:
  81.                     print("Incorrect password of username")
  82.             else:
  83.                 print("username doesn't exist")
  84.         except:
  85.             print("Login error")
  86.  
  87.        
  88. #register and add into the txt file 
  89. def register():  
  90.     success = False
  91.     db = open("user_loggin.txt","r")
  92.     Username = input("Create your username: ")
  93.     Password = input("Create your password: ")
  94.     Password1 = input("Confirm your password: ")
  95.     d=[]
  96.     f=[]
  97.     for i in db:
  98.         a,b = i.split(",")
  99.         b = b.strip()
  100.         d.append(a)
  101.         f.append(b)
  102.     data = dict(zip(d,f))
  103.     #print(data)
  104.         
  105.     if Password != Password1:
  106.         print("Passwords don't match, restart")
  107.         register()
  108.     else:
  109.         if len(Password)<=6:
  110.             print("Password too short, restart")
  111.             register()
  112.         elif Username in d:
  113.             print("Username exists!")
  114.             register()
  115.         else:
  116.             db = open("user_loggin.txt", "a")
  117.             db.write(Username+","+Password+"\n")
  118.             print("Successfully Register!")
  119.         return homepage()    
  120.  
  121. #home page 
  122. def homepage():
  123.     screen_clear()
  124.     print("  _____________________________________________")
  125.     print("  | Welcome to Bus station ticket !           |")
  126.     print("  | Enter [x] to enable screen clear mode     |")
  127.     print("  | Enter [1] to log in into existed account  |")
  128.     print("  | Enter [2] to register new account         |")
  129.     print("  | Enter [3] to exit from the programme      |")
  130.     print("  ---------------------------------------------")
  131.     choice = input("PLease Enter according to your needs :")
  132.     return choice
  133.  
  134. #function for home page 
  135. def main():  
  136.     global name
  137.       
  138.     print("This plastform is", os.name)
  139.     exitProgram = False
  140.     while exitProgram == False :
  141.         choice = homepage()
  142.         if choice == 'x' or choice == 'X':
  143.             ClearScreenSetting()
  144.         elif choice == '1':
  145.             login()
  146.         elif choice == '2':
  147.             register()
  148.         elif choice =='3' :
  149.             print("Thank you for using our website !")
  150.             exitProgram = True
  151.             
  152.             
  153.  
  154. main()

Editor

You can edit this paste and save as new:


File Description
  • module 1
  • Paste Code
  • 20 Sep-2021
  • 4.5 Kb
You can Share it: