Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def displayName():
- """ This is a procedure which will ask the user for the name of their
- vet surgery, and then welcome them using the name they have just
- input into the program.
- """
- surgery = input("What is the name of the Vet Surgery? > ")
- print("Welcome to the {0} Veterinary Surgery.".format(surgery))
- menuProgram() #Takes user back to subprogram selection.
- #---------------------------------------------------------------------------------------
- def checkUsernamePassword():
- """ This is a procedure which will ask the user for their username
- and password, and if they get a valid username and password
- they will get the message 'valid username and password', but if
- either the username or password are incorrect, the program will
- display 'invalid username and password'.
- """
- username = input("Please enter your username > ")
- password = input("Please enter your password > ")
- while username != "admin" or password != "ABC123*":
- print("Invalid username or password.")
- username = input("Please enter your username > ")
- password = input("Please enter your password > ")
- print ("Valid username and password.")
- #---------------------------------------------------------------------------------------
- def totalCost(mylist):
- """ This is a function which will calculate the total of a given
- list in a 'for' loop, and return the value to the main program.
- """
- cost = 0
- for element in mylist:
- cost = cost + element
- return cost
- #---------------------------------------------------------------------------------------
- def writeToFile():
- """ This is a function that allows the user to enter the firstname
- and surname of the owner, the name of the pet and the type of animal-
- this information will then be written to file.
- """
- answer = "Y" #Sets the initial guard variable to "Y" so that the program will enter
- #the while loop at least once.
- while answer == "Y":
- animalfile = open("animals.txt","a") #Opens the file 'animals.txt' (or will create
- #a file of the same name if it doesn't already
- #exist) in append mode, so that data isn't overwritten
- #every time the program runs.
- firstname = input("Enter first name of owner > ") #Asking for the data to be appended onto file
- surname = input("Enter surname of owner > ") # |
- petname = input("Enter pet name > ") # |
- animaltype = input("Enter type of animal > ") # v
- record = "{0} {1} {2} {3} \n".format(firstname, surname, petname, animaltype)
- #The variable 'record' is comprised of the 4 seperate variables created above- they are compiled
- #into the new variable 'record' so it only requires one 'fileName.write()' command as opposed
- #to four seperate ones.
- animalfile.write(record) #Writes the contents of the variable 'record onto the file'
- answer = input("Do you want to enter another customer Y/N ? > ") #Asks the user whether they would
- validList = ["Y","N"] #A list of valid answers #like to continue or not
- while answer not in validList: #Checks whether the users answer is in the valid list or not.
- #User will enter this while loop if it is not "Y" or "N"
- print("Invalid selection. Please choose again.")
- answer = input("Do you want to enter another customer Y/N ? > ")
- animalfile.close() #Closes the file so that other programs may access it.
- menuProgram() #Takes user back to subprogram selection.
- #---------------------------------------------------------------------------------------
- """ MAIN PROGRAM- Computer System for the Red Bank Veterinary Surgery
- """
- print("LOGIN TO SYSTEM:") #Initial login- must do this before you can access other programs
- checkUsernamePassword()
- def menuProgram():
- """ This is the menu which enables you to choose which sub-program you would like to run.
- """
- print ("MENU:\n\n PRESS:\n\t1 for Welcome Message Program\n\t2 for Fluffy's Total Cost Program")
- print("\t3 for Patient Input Program\n\t0 to quit the program.")
- choice = input(" > ")
- if choice == "1":
- displayName() # First Sub-Program
- elif choice == "2":
- fluffy = [10,5,8,20,8] #Third Sub-
- totalcost = totalCost(fluffy) #Program
- print("Total cost for fluffy is £{0}.".format(totalcost))
- menuProgram()
- elif choice == "3":
- writeToFile() #Fourth Sub-
- #Program
- elif choice == "0":
- print("Goodbye.")
- else:
- print("I didn't quite get that.")
- menuProgram()
- menuProgram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement