Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mainMenu():
- print("""
- ###############################################################################
- # #
- # Clive's Carpets #
- # Please Login Below! #
- # #
- ###############################################################################
- """)
- validateUser()
- def adminMenu():
- while True:
- print("""
- ###############################################################################
- # #
- # Clive's Carpets #
- # Admin Menu #
- # #
- # 1 - Add a New User #
- # 2 - Quotes #
- # 3 - Exit #
- # #
- ###############################################################################
- """)
- adminMenu = input("Which option would you like to choose? '1' , '2' or '3': ")
- if adminMenu == "1":
- userInput()
- break
- elif adminMenu == "2":
- quoteMenu()
- break
- elif adminMenu == "3":
- exit()
- break
- def userMenu():
- print("\nUser Menu")
- userMenu = input("\nDo you wish to create a new quote? 'Yes' 'No': ")
- if userMenu.lower() == "yes":
- newQuote()
- elif userMenu.lower() == "no":
- exit()
- else:
- userMenu()
- def newQuote():
- while True:
- try:
- Width = float(input("\nWhat is the width of your room? (Carpets are £22.50 per m²): "))
- Length = float(input("\nWhat is the length of your room?: "))
- while True:
- Undercarpet = input("Which Undercarpet would you like:\nFirst Step (£5.99 per m²)\nMonarch (£7.99 per m²)\nRoyal (£60.00 per m²)\n")
- if Undercarpet.lower() == "first step":
- UndercarpetPrice = 5.99
- elif Undercarpet.lower() == "monarch":
- UndercarpetPrice = 7.99
- elif Undercarpet.lower() == "royal":
- UndercarpetPrice = 60.00
- else:
- print("Please choose a valid undercarpet option")
- continue
- break
- Carpet = Width*Length
- CarpetP = Width + Width + Length + Length
- CarpetPrice = 22.50 * Carpet
- GripperPrice = 1.10 * CarpetP
- UndercarpetPrice = UndercarpetPrice * Carpet
- LabourHours = Carpet / 16
- LabourPrice = 65 * LabourHours
- CarpetTotal = CarpetPrice + GripperPrice + UndercarpetPrice + LabourPrice
- print("The total price for your carpet after adding the labour costs (£65 per hour): £" +str(CarpetTotal))
- break
- except:
- print("\nPlease enter a number")
- WidthStore = str(Width).ljust(10)
- LengthStore = str(Length).ljust(10)
- CarpetStore = str(Carpet).ljust(10)
- CarpetPStore = str(CarpetP).ljust(10)
- CarpetPriceStore = str(CarpetPrice).ljust(10)
- GripperPriceStore = str(GripperPrice).ljust(10)
- UndercarpetStore = Undercarpet.ljust(10)
- UndercarpetPriceStore = str(UndercarpetPrice).ljust(10)
- LabourHoursStore = str(LabourHours).ljust(10)
- LabourPriceStore = str(LabourPrice).ljust(10)
- CarpetTotalStore = str(CarpetTotal).ljust(10)
- store = open ("quotes.txt","a")
- iStore = WidthStore + LengthStore + CarpetStore + CarpetPStore + CarpetPriceStore + UndercarpetPriceStore + LabourHoursStore + LabourPriceStore + CarpetTotalStore + "\n"
- store.write(iStore)
- store.close()
- def quoteMenu():
- quoteMenu()
- def userInput():
- userType, username, password1, password2 = "", "", "", ""
- while True:
- userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
- if userType == "-1":
- mainMenu()
- if len(userType) > 1:
- print("\nInvalid Input.\n")
- elif userType.isdigit() != True:
- print("Please enter a number!")
- elif int(userType) <1:
- print("\nInvalid Input.\n")
- elif int(userType) >2:
- print("\nInvalid Input.\n")
- else:
- break
- while True:
- username = input("\nPlease enter the username of the new user: ")
- if username == "-1":
- mainMenu()
- if len(username) >10:
- print("\nThe username must be less than 11 characters.\n")
- elif username.isalpha() == False:
- print("\nThe username must only contain alpha.\n")
- else:
- break
- while True:
- password1 = input("\nPlease enter the password for the user: ")
- if password1 == "-1":
- mainMenu()
- if len(password1) > 10:
- print("\nThe password must be less than 11 characters.\n")
- password2 = input("\nPlease enter the password again: ")
- if password2 == "-1":
- mainMenu()
- if len(password2) > 10:
- print("\nThe password must be less than 11 characters.\n")
- if password1 != password2:
- print("\nThe password does not match,retry.\n")
- else:
- break
- while True:
- FirstName = input("\nPlease enter your first name: ")
- if FirstName == "-1":
- mainMenu()
- if len(FirstName) >25:
- print("\nYour first name must be less than 25 characters.\n")
- else:
- break
- while True:
- Surname = input("\nPlease enter your surname: ")
- if Surname == "-1":
- mainMenu()
- if len(Surname) >25:
- print("\nYour surname must be less than 25 characters.\n")
- else:
- break
- while True:
- Telephone = input("\nPlease enter your telephone: ")
- try:
- int(Telephone)
- except:
- print("The telephone number must be a number")
- if Telephone == "-1":
- mainMenu()
- if len(Telephone) >16:
- print("\nThe telephone number must be less than 16 characters.\n")
- else:
- break
- while True:
- Town = input("\nPlease enter your town: ")
- if Town == "-1":
- mainMenu()
- if len(Town) >15:
- print("\nYour town must be less than 15 characters.\n")
- else:
- break
- username = username.lower()
- password1 = password1.lower()
- password2 = password2.lower()
- FirstName = FirstName.lower()
- Surname = Surname.lower()
- Telephone = Telephone.lower()
- Town = Town.lower()
- userTypeStore = str(userType).ljust(2)
- usernameStore = username.ljust(10)
- passwordStore = password1.ljust(10)
- FirstNameStore = FirstName.ljust(25)
- SurnameStore = Surname.ljust(25)
- TelephoneStore = Telephone.ljust(16)
- TownStore = Town.ljust(15)
- store = open("users.txt","a")
- iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + TownStore + "\n"
- store.write(iStore)
- store.close()
- print("\nNew User Created: ")
- print("Usertype: ",userType)
- print("Username: ",username)
- print("Password: ",("*"*len(password1)))
- print("First Name: ",FirstName)
- print("Surname: ",Surname)
- print("Telephone: ",Telephone)
- print("Town: ",Town)
- mainMenu()
- def validateUser():
- validateUserType = ""
- validateUsername = ""
- validatePassword = ""
- username = str(input("\nPlease enter your username: \n"))
- password = str(input("\nPlease enter your password: \n"))
- while True:
- try:
- readUsers = open("users.txt","r")
- validateCounter = 0
- while True:
- location = readUsers.readline()
- validateUserType = location[20:22]
- validateUserType = validateUserType.strip()
- validateUsername = location [0:10]
- validateUsername = validateUsername.strip()
- validateUsername = validateUsername.lower()
- username = username.lower()
- validatePassword = location[10:20]
- validatePassword = validatePassword.strip()
- validatePassword = validatePassword.lower()
- password = password.lower()
- if location == "":
- readUsers.close()
- break
- if validateUserType == str(1) and validateUsername == username and validatePassword == password:
- validateCounter = validateCounter + 1
- adminMenu()
- break
- if validateUserType == str(2) and validateUsername == username and validatePassword == password:
- validateCounter = validateCounter + 1
- userMenu()
- break
- if validateCounter ==0:
- print("\nThere is no user in the file with those login details. \n")
- validateUser()
- except FileNotFoundError:
- 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")
- userInput()
- def main():
- mainMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement