[text] Module2New

Viewer

copydownloadembedprintName: Module2New
  1. import os
  2. from datetime import datetime
  3. enableCLS = False
  4.  
  5. def screen_clear():
  6.     if enableCLS:
  7.         print("Screen_clear is ON ! ")
  8.         if os.name == 'posix':
  9.             _ = os.system('clear')
  10.         else:
  11.             _ = os.system('cls')
  12.     else:
  13.         print("screen clear is off !")
  14.  
  15. def ClearScreenSetting():
  16.     global enableCLS
  17.     ch = input("\nDo you want to enable \"Clear screen\"?\n\Press Y for yes , any other keys for NO : ")
  18.     if ch == 'Y' or ch == 'y':
  19.         enableCLS = True
  20.     else:
  21.         enableCLS = False
  22.  
  23. #create bus
  24. def createBus():
  25.     file = open("bus.txt", "a")
  26.     bus_ID = input("Enter bus ID in format: bus number_destination Town. Example: 2344_Kajang: ")
  27.     date = str(input("Enter departure date(yyyy-mm-dd):"))
  28.     time = str(input("Enter departure time(hh:mm)): " ))
  29.     dtown = str(input("Departure town: "))
  30.     atown = str(input("Arrival town: "))
  31.     seat = int(input("Total seat available: "))
  32.     fare = float(input("Fare per seat: "))
  33.     file.write("\n" +str(bus_ID)+ "," +str(date)+ "," +str(time)+ "," +dtown+ "," +atown+ "," +str(seat)+ "," +str(fare)+"\n")
  34.     file.close()
  35.     print("Bus created successfully")
  36.  
  37. #edit bus
  38. def editBus():
  39.     file = open("bus.txt")
  40.     print(file.read())
  41.     bus_ID = input("Enter bus ID in format: bus number_destination Town. Example: 2344_Klang: ")
  42.     if (bus_ID in file.read()):
  43.         if seat >= 42:
  44.             file = open("bus.txt", "w")
  45.             file.close()
  46.         else:
  47.             print("You cannot edit the bus information because it is booked")
  48.     else:
  49.         print("You cannot edit the bus information because it does not exist")
  50.  
  51.     bus()
  52.  
  53. #homepage
  54. def bus():
  55.     screen_clear()
  56.     print("  _____________________________________________")
  57.     print("  | Welcome to Bus Information System !        |")
  58.     print("  | Enter [x] to enable screen clear mode      |")
  59.     print("  | Enter [1] to view existing bus             |")
  60.     print("  | Enter [2] to register new bus              |")
  61.     print("  | Enter [3] to edit empty exixting bus       |")
  62.     print("  | Enter [4] to delete bus                    |")
  63.     print("  | Enter [5] to exit from the programme       |")
  64.     print("  ----------------------------------------------")
  65.     choice = input("PLease Enter according to your needs :")
  66.     return choice
  67.  
  68.  
  69. def main():  # function before login
  70.     global bus_ID
  71.  
  72.     print("This plastform is", os.name)
  73.     exitProgram = False
  74.     while exitProgram == False:
  75.         choice = bus()
  76.         if choice == 'x' or choice == 'X':
  77.             ClearScreenSetting()
  78.         elif choice == '1':
  79.             bus_ID = input("Enter bus ID: ")
  80.             if bus_ID == False:
  81.                 print("Please enter a valid bus ID")
  82.             else:
  83.                 viewBus(bus_ID)
  84.  
  85.         elif choice == '2':
  86.             createBus()
  87.             input("Bus information created successfully !! [Enter any key to continue] ")
  88.             bus()
  89.  
  90.         elif choice == '3':
  91.             editBus()
  92.             input("Bus information edited succesfully !! [Enter any key to continue] ")
  93.             bus()
  94.  
  95.         elif choice == '4':
  96.             delBus()
  97.             input("Bus information deleted !! [Enter any key to continue] ")
  98.             bus()
  99.  
  100.         elif choice == '5':
  101.             print("Thank you for using our website !")
  102.             exitProgram = True
  103.  
  104.  
  105. main()

Editor

You can edit this paste and save as new:


File Description
  • Module2New
  • Paste Code
  • 21 Sep-2021
  • 3.41 Kb
You can Share it: