Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.07 KB | None | 0 0
  1. def mainMenu():
  2. print("""
  3. ###############################################################################
  4. # #
  5. # Clive's Carpets #
  6. # Please Login Below! #
  7. # #
  8. ###############################################################################
  9. """)
  10. validateUser()
  11.  
  12. def adminMenu():
  13. while True:
  14. print("""
  15. ###############################################################################
  16. # #
  17. # Clive's Carpets #
  18. # Admin Menu #
  19. # #
  20. # 1 - Add a New User #
  21. # 2 - Quotes #
  22. # 3 - Exit #
  23. # #
  24. ###############################################################################
  25. """)
  26.  
  27. adminMenu = input("Which option would you like to choose? '1' , '2' or '3': ")
  28. if adminMenu == "1":
  29. userInput()
  30. break
  31. elif adminMenu == "2":
  32. quoteMenu()
  33. break
  34. elif adminMenu == "3":
  35. exit()
  36. break
  37.  
  38.  
  39. def userMenu():
  40. print("\nUser Menu")
  41. userMenu = input("\nDo you wish to create a new quote? 'Yes' 'No': ")
  42. if userMenu.lower() == "yes":
  43. newQuote()
  44. elif userMenu.lower() == "no":
  45. exit()
  46. else:
  47. userMenu()
  48.  
  49. def newQuote():
  50. while True:
  51. try:
  52. Width = float(input("\nWhat is the width of your room? (Carpets are £22.50 per m²): "))
  53. Length = float(input("\nWhat is the length of your room?: "))
  54. while True:
  55. Undercarpet = input("Which Undercarpet would you like:\nFirst Step (£5.99 per m²)\nMonarch (£7.99 per m²)\nRoyal (£60.00 per m²)\n")
  56. if Undercarpet.lower() == "first step":
  57. UndercarpetPrice = 5.99
  58. elif Undercarpet.lower() == "monarch":
  59. UndercarpetPrice = 7.99
  60. elif Undercarpet.lower() == "royal":
  61. UndercarpetPrice = 60.00
  62. else:
  63. print("Please choose a valid undercarpet option")
  64. continue
  65. break
  66.  
  67. Carpet = Width*Length
  68. CarpetP = Width + Width + Length + Length
  69. CarpetPrice = 22.50 * Carpet
  70. GripperPrice = 1.10 * CarpetP
  71. UndercarpetPrice = UndercarpetPrice * Carpet
  72. LabourHours = Carpet / 16
  73. LabourPrice = 65 * LabourHours
  74. CarpetTotal = CarpetPrice + GripperPrice + UndercarpetPrice + LabourPrice
  75. print("The total price for your carpet after adding the labour costs (£65 per hour): £" +str(CarpetTotal))
  76. break
  77. except:
  78. print("\nPlease enter a number")
  79.  
  80. WidthStore = str(Width).ljust(10)
  81. LengthStore = str(Length).ljust(10)
  82. CarpetStore = str(Carpet).ljust(10)
  83. CarpetPStore = str(CarpetP).ljust(10)
  84. CarpetPriceStore = str(CarpetPrice).ljust(10)
  85. GripperPriceStore = str(GripperPrice).ljust(10)
  86. UndercarpetStore = Undercarpet.ljust(10)
  87. UndercarpetPriceStore = str(UndercarpetPrice).ljust(10)
  88. LabourHoursStore = str(LabourHours).ljust(10)
  89. LabourPriceStore = str(LabourPrice).ljust(10)
  90. CarpetTotalStore = str(CarpetTotal).ljust(10)
  91.  
  92. store = open ("quotes.txt","a")
  93. iStore = WidthStore + LengthStore + CarpetStore + CarpetPStore + CarpetPriceStore + UndercarpetPriceStore + LabourHoursStore + LabourPriceStore + CarpetTotalStore + "\n"
  94. store.write(iStore)
  95. store.close()
  96.  
  97. def quoteMenu():
  98.  
  99. quoteMenu()
  100. def userInput():
  101. userType, username, password1, password2 = "", "", "", ""
  102. while True:
  103.  
  104. userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
  105. if userType == "-1":
  106. mainMenu()
  107. if len(userType) > 1:
  108. print("\nInvalid Input.\n")
  109. elif userType.isdigit() != True:
  110. print("Please enter a number!")
  111. elif int(userType) <1:
  112. print("\nInvalid Input.\n")
  113. elif int(userType) >2:
  114. print("\nInvalid Input.\n")
  115. else:
  116. break
  117. while True:
  118. username = input("\nPlease enter the username of the new user: ")
  119. if username == "-1":
  120. mainMenu()
  121. if len(username) >10:
  122. print("\nThe username must be less than 11 characters.\n")
  123. elif username.isalpha() == False:
  124. print("\nThe username must only contain alpha.\n")
  125. else:
  126. break
  127. while True:
  128. password1 = input("\nPlease enter the password for the user: ")
  129. if password1 == "-1":
  130. mainMenu()
  131. if len(password1) > 10:
  132. print("\nThe password must be less than 11 characters.\n")
  133. password2 = input("\nPlease enter the password again: ")
  134. if password2 == "-1":
  135. mainMenu()
  136. if len(password2) > 10:
  137. print("\nThe password must be less than 11 characters.\n")
  138. if password1 != password2:
  139. print("\nThe password does not match,retry.\n")
  140. else:
  141. break
  142. while True:
  143. FirstName = input("\nPlease enter your first name: ")
  144. if FirstName == "-1":
  145. mainMenu()
  146. if len(FirstName) >25:
  147. print("\nYour first name must be less than 25 characters.\n")
  148. else:
  149. break
  150. while True:
  151. Surname = input("\nPlease enter your surname: ")
  152. if Surname == "-1":
  153. mainMenu()
  154. if len(Surname) >25:
  155. print("\nYour surname must be less than 25 characters.\n")
  156. else:
  157. break
  158. while True:
  159. Telephone = input("\nPlease enter your telephone: ")
  160. try:
  161. int(Telephone)
  162. except:
  163. print("The telephone number must be a number")
  164. if Telephone == "-1":
  165. mainMenu()
  166. if len(Telephone) >16:
  167. print("\nThe telephone number must be less than 16 characters.\n")
  168. else:
  169. break
  170. while True:
  171. Town = input("\nPlease enter your town: ")
  172. if Town == "-1":
  173. mainMenu()
  174. if len(Town) >15:
  175. print("\nYour town must be less than 15 characters.\n")
  176. else:
  177. break
  178.  
  179.  
  180.  
  181. username = username.lower()
  182. password1 = password1.lower()
  183. password2 = password2.lower()
  184. FirstName = FirstName.lower()
  185. Surname = Surname.lower()
  186. Telephone = Telephone.lower()
  187. Town = Town.lower()
  188.  
  189. userTypeStore = str(userType).ljust(2)
  190. usernameStore = username.ljust(10)
  191. passwordStore = password1.ljust(10)
  192. FirstNameStore = FirstName.ljust(25)
  193. SurnameStore = Surname.ljust(25)
  194. TelephoneStore = Telephone.ljust(16)
  195. TownStore = Town.ljust(15)
  196.  
  197. store = open("users.txt","a")
  198. iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + TownStore + "\n"
  199. store.write(iStore)
  200. store.close()
  201.  
  202. print("\nNew User Created: ")
  203. print("Usertype: ",userType)
  204. print("Username: ",username)
  205. print("Password: ",("*"*len(password1)))
  206. print("First Name: ",FirstName)
  207. print("Surname: ",Surname)
  208. print("Telephone: ",Telephone)
  209. print("Town: ",Town)
  210.  
  211. mainMenu()
  212.  
  213.  
  214. def validateUser():
  215. validateUserType = ""
  216. validateUsername = ""
  217. validatePassword = ""
  218.  
  219. username = str(input("\nPlease enter your username: \n"))
  220. password = str(input("\nPlease enter your password: \n"))
  221.  
  222. while True:
  223. try:
  224. readUsers = open("users.txt","r")
  225. validateCounter = 0
  226.  
  227. while True:
  228. location = readUsers.readline()
  229. validateUserType = location[20:22]
  230. validateUserType = validateUserType.strip()
  231.  
  232. validateUsername = location [0:10]
  233. validateUsername = validateUsername.strip()
  234. validateUsername = validateUsername.lower()
  235. username = username.lower()
  236.  
  237. validatePassword = location[10:20]
  238. validatePassword = validatePassword.strip()
  239. validatePassword = validatePassword.lower()
  240. password = password.lower()
  241.  
  242.  
  243.  
  244. if location == "":
  245. readUsers.close()
  246. break
  247. if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  248. validateCounter = validateCounter + 1
  249. adminMenu()
  250. break
  251. if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  252. validateCounter = validateCounter + 1
  253. userMenu()
  254. break
  255.  
  256. if validateCounter ==0:
  257. print("\nThere is no user in the file with those login details. \n")
  258. validateUser()
  259. except FileNotFoundError:
  260. print("There is no Users file for you to search! How about making your first account?\nTop Tip, make it a System Administrator Account!\n")
  261. userInput()
  262.  
  263. def main():
  264. mainMenu()
  265.  
  266.  
  267. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement