fork download
  1. import os
  2. import platform
  3. import mysql.connector
  4.  
  5. def connect_db():
  6. return mysql.connector.connect(host="localhost", user="root", password="root", database='parking')
  7.  
  8. def Add_Record(mycursor):
  9. L = []
  10. id1 = int(input("Enter the parking number : "))
  11. L.append(id1)
  12. pname1 = input("Enter the Parking Name: ")
  13. L.append(pname1)
  14. level1 = input("Enter level of parking : ")
  15. L.append(level1)
  16. freespace1 = input("Is there any freespace or not : YES/NO ")
  17. L.append(freespace1)
  18. vehicleno1 = input("Enter the Vehicle Number : ")
  19. L.append(vehicleno1)
  20. nod1 = int(input("Enter total number of days for parking: "))
  21. L.append(nod1)
  22.  
  23. # Payment calculation
  24. Payment1 = 20 * nod1 if nod1 <= 5 else 6969
  25. L.append(Payment1)
  26.  
  27. stud = tuple(L)
  28. sql = 'INSERT INTO parkmaster12(pid, pnm, level, freespace, vehicleno, nod, payment) VALUES(%s, %s, %s, %s, %s, %s, %s)'
  29. mycursor.execute(sql, stud)
  30.  
  31. def Rec_View(mycursor):
  32. print("Select the search criteria : ")
  33. print("1. Parking Number")
  34. print("2. Parking Name")
  35. print("3. Level No")
  36. print("4. All")
  37. ch = int(input("Enter the choice : "))
  38.  
  39. if ch == 1:
  40. s = int(input("Enter Parking no : "))
  41. sql = "SELECT * FROM parkmaster12 WHERE pid=%s"
  42. mycursor.execute(sql, (s,))
  43. elif ch == 2:
  44. s = input("Enter Parking Name : ")
  45. sql = "SELECT * FROM parkmaster12 WHERE pnm=%s"
  46. mycursor.execute(sql, (s,))
  47. elif ch == 3:
  48. s = input("Enter Level of Parking : ")
  49. sql = "SELECT * FROM parkmaster12 WHERE level=%s"
  50. mycursor.execute(sql, (s,))
  51. elif ch == 4:
  52. sql = "SELECT * FROM parkmaster12"
  53. mycursor.execute(sql)
  54.  
  55. res = mycursor.fetchall()
  56. print("Details about Parking are as follows : ")
  57. print("(Parking Id, Parking Name, Level, FreeSpace(Y/N), Vehicle No, No of days for parking, Payment)")
  58. for x in res:
  59. print(x)
  60.  
  61. def Vehicle_Detail(mycursor):
  62. L = []
  63. vid1 = int(input("Enter Vehicle No : "))
  64. L.append(vid1)
  65. vnm1 = input("Enter Vehicle Name/Model Name : ")
  66. L.append(vnm1)
  67. dateofpur1 = input("Enter Year-Month-Date of purchase : ")
  68. L.append(dateofpur1)
  69. vdt = tuple(L)
  70. sql = "INSERT INTO vehicle(vid, vnm, dateofpur) VALUES(%s, %s, %s)"
  71. mycursor.execute(sql, vdt)
  72.  
  73. def Vehicle_View(mycursor):
  74. vid1 = int(input("Enter the vehicle number of the vehicle whose details is to be viewed : "))
  75. sql = 'SELECT parkmaster12.pid, parkmaster12.pnm, parkmaster12.vehicleno, vehicle.vid, vehicle.vnm FROM parkmaster12 INNER JOIN vehicle ON parkmaster12.pid=vehicle.vid WHERE vehicle.vid=%s'
  76. mycursor.execute(sql, (vid1,))
  77. res = mycursor.fetchall()
  78. print('The following are the details you wanted:')
  79. for x in res:
  80. print(x)
  81.  
  82. def remove(mycursor):
  83. vid1 = int(input("Enter the vehicle number of the vehicle to be deleted : "))
  84. sql = "DELETE FROM vehicle WHERE vid=%s"
  85. mycursor.execute(sql, (vid1,))
  86. print('Removed as per the command')
  87.  
  88. def Menu(mycursor):
  89. print("Enter 1 : To Add Parking Detail")
  90. print("Enter 2 : To View Parking Detail ")
  91. print("Enter 3 : To Add Vehicle Detail ")
  92. print("Enter 4 : To Remove Vehicle Record")
  93. print("Enter 5 : To see the details of Vehicle")
  94. input_dt = int(input("Please Select An Above Option: "))
  95.  
  96. if input_dt == 1:
  97. Add_Record(mycursor)
  98. elif input_dt == 2:
  99. Rec_View(mycursor)
  100. elif input_dt == 3:
  101. Vehicle_Detail(mycursor)
  102. elif input_dt == 4:
  103. remove(mycursor)
  104. elif input_dt == 5:
  105. Vehicle_View(mycursor)
  106. else:
  107. print("Enter correct choice....")
  108.  
  109. def run():
  110. mydb = connect_db()
  111. mycursor = mydb.cursor()
  112. while True:
  113. Menu(mycursor)
  114. runAgn = input('\nWant to run Again Y/n: ')
  115. if runAgn.lower() != 'y':
  116. break
  117. mydb.close()
  118.  
  119. run()
  120.  
Success #stdin #stdout 0.02s 25804KB
stdin
Standard input is empty
stdout
import os
import platform
import mysql.connector

def connect_db():
    return mysql.connector.connect(host="localhost", user="root", password="root", database='parking')

def Add_Record(mycursor):
    L = []
    id1 = int(input("Enter the parking number : "))
    L.append(id1)
    pname1 = input("Enter the Parking Name: ")
    L.append(pname1)
    level1 = input("Enter level of parking : ")
    L.append(level1)
    freespace1 = input("Is there any freespace or not : YES/NO ")
    L.append(freespace1)
    vehicleno1 = input("Enter the Vehicle Number : ")
    L.append(vehicleno1)
    nod1 = int(input("Enter total number of days for parking: "))
    L.append(nod1)

    # Payment calculation
    Payment1 = 20 * nod1 if nod1 <= 5 else 6969
    L.append(Payment1)

    stud = tuple(L)
    sql = 'INSERT INTO parkmaster12(pid, pnm, level, freespace, vehicleno, nod, payment) VALUES(%s, %s, %s, %s, %s, %s, %s)'
    mycursor.execute(sql, stud)

def Rec_View(mycursor):
    print("Select the search criteria : ")
    print("1. Parking Number")
    print("2. Parking Name")
    print("3. Level No")
    print("4. All")
    ch = int(input("Enter the choice : "))
    
    if ch == 1:
        s = int(input("Enter Parking no : "))
        sql = "SELECT * FROM parkmaster12 WHERE pid=%s"
        mycursor.execute(sql, (s,))
    elif ch == 2:
        s = input("Enter Parking Name : ")
        sql = "SELECT * FROM parkmaster12 WHERE pnm=%s"
        mycursor.execute(sql, (s,))
    elif ch == 3:
        s = input("Enter Level of Parking : ")
        sql = "SELECT * FROM parkmaster12 WHERE level=%s"
        mycursor.execute(sql, (s,))
    elif ch == 4:
        sql = "SELECT * FROM parkmaster12"
        mycursor.execute(sql)

    res = mycursor.fetchall()
    print("Details about Parking are as follows : ")
    print("(Parking Id, Parking Name, Level, FreeSpace(Y/N), Vehicle No, No of days for parking, Payment)")
    for x in res:
        print(x)

def Vehicle_Detail(mycursor):
    L = []
    vid1 = int(input("Enter Vehicle No : "))
    L.append(vid1)
    vnm1 = input("Enter Vehicle Name/Model Name : ")
    L.append(vnm1)
    dateofpur1 = input("Enter Year-Month-Date of purchase : ")
    L.append(dateofpur1)
    vdt = tuple(L)
    sql = "INSERT INTO vehicle(vid, vnm, dateofpur) VALUES(%s, %s, %s)"
    mycursor.execute(sql, vdt)

def Vehicle_View(mycursor):
    vid1 = int(input("Enter the vehicle number of the vehicle whose details is to be viewed : "))
    sql = 'SELECT parkmaster12.pid, parkmaster12.pnm, parkmaster12.vehicleno, vehicle.vid, vehicle.vnm FROM parkmaster12 INNER JOIN vehicle ON parkmaster12.pid=vehicle.vid WHERE vehicle.vid=%s'
    mycursor.execute(sql, (vid1,))
    res = mycursor.fetchall()
    print('The following are the details you wanted:')
    for x in res:
        print(x)

def remove(mycursor):
    vid1 = int(input("Enter the vehicle number of the vehicle to be deleted : "))
    sql = "DELETE FROM vehicle WHERE vid=%s"
    mycursor.execute(sql, (vid1,))
    print('Removed as per the command')

def Menu(mycursor):
    print("Enter 1 : To Add Parking Detail")
    print("Enter 2 : To View Parking Detail ")
    print("Enter 3 : To Add Vehicle Detail ")
    print("Enter 4 : To Remove Vehicle Record")
    print("Enter 5 : To see the details of Vehicle")
    input_dt = int(input("Please Select An Above Option: "))
    
    if input_dt == 1:
        Add_Record(mycursor)
    elif input_dt == 2:
        Rec_View(mycursor)
    elif input_dt == 3:
        Vehicle_Detail(mycursor)
    elif input_dt == 4:
        remove(mycursor)
    elif input_dt == 5:
        Vehicle_View(mycursor)
    else:
        print("Enter correct choice....")

def run():
    mydb = connect_db()
    mycursor = mydb.cursor()
    while True:
        Menu(mycursor)
        runAgn = input('\nWant to run Again Y/n: ')
        if runAgn.lower() != 'y':
            break
    mydb.close()

run()