SRT111 – Fall 2021 Assignment #2 Submission Instructions Please submit your full python code in a file that must be named like YourName_Assignment2.ipynb or YourName_Assignment2.py. You must submit...

its in the attachment


SRT111 – Fall 2021 Assignment #2 Submission Instructions Please submit your full python code in a file that must be named like YourName_Assignment2.ipynb or YourName_Assignment2.py. You must submit python code; no PDF files will be marked! The professor can call any student for a one on one interview to explain the code and answer some questions about the code. Failing to participate in this interview will result in a grade of zero in the assignment. General Description: In this assignment, you will be writing a python program that can be used to edit, as well as to access the information contained in a database called students.dat. Please open the “students.dat” file with notepad or notepad++. This database contains information about each student saved in a specific format in a line. A colon (:) separates the fields. For example, a student record with the following information: ID: 1234 Name: Anne Shirley Semester: 2 Year: 1 Number Of Courses: 5 Will be stored in this database as the following line: 1234:Anne Shirley:2:1:5 A database file “students.dat” is provided on Blackboard. You can use this database to test your own program. Make sure to save a backup of this database before using it. Specific Instructions: Below is the skeleton for your script. Your task will be to write the contents of four functions in the provided spaces. # Write down your name and student id # SRT111 Assignment 2 # I vouch that this program contains only lines of code provided by the instructor or written by myself. I did not collaborate with other students, or showed my work to anyone. #def main: #write the contents of your main function here While True: # Code for menu if choice == "a": add_student elif choice == "e": edit_student elif choice == "r": remove_student elif choice == "i": get_info elif choice == "q": break else echo "Invalid choice, please enter a valid choice!" # #def add_student: #write the contents of your add_student function here #} #def remove_student: #write the contents of your remove_student function here #} #def edit_student: #write the contents of your edit_student function here #} #function get_info { #write the contents of your get_info function here #} Below, we provide a description of what each function should do: Main() [1.0 marks] This function should greet the user to the program and then ask the user what he/she wants to do. The options are [a]: add_studen, [e]: edit student, [r]: remove student, [i]: get info about a student, and [q]: quit. Note that this function should save the user’s input in a variable called choice. Possible values to be saved in choice are: “a”, “e”, “r”, “i”, or “q”. add_student [2.0 marks] This function, as the name suggests, is used to add new student record to the bottom of database file. It should do the following: 1. It starts by asking the user all the required information about the student you want to add, i.e., name, id, semester, year and number of courses in the semester. Please note that “:” (colon) is a field separator in the database file, make sure that user does not enter a colon in any of the input values. 2. After getting all necessary information, this function should save it as a line in the database, i.e. the student.dat file, following the same format as presented above for student having id 1234. Note that, before adding the new student, this function must check if the chosen id is already in use in the database. In case there is already a student with this same id, your script should print that a student with this id already exists and then keep asking the user if he/she wants to try a new id or wants to go back to the main menu (i.e. the menu function). Failing to perform this check will result in the loss of “1” mark. edit_student [2.0 marks] This function, as the name suggests, edits information about a student record in the database. It can only edit three fields: the year, the semester and the number of courses. 1. It starts by asking the id of the student record you want to edit. In case the id does not exist, your function should ask for a new id, or ask if the user wants to go back to the main menu (i.e. the menu function call at the beginning of the loop). 2. In case the id exists, the function should ask which field to edit: [y]ear or [s]emester or [c]ourses. In case a wrong answer is given, your script should keep asking for a valid answer or some option for going back to main function. 3. Finally, this function should ask the new value for the field and save it in the studnent.dat file. This time don’t add a new record, your program should update the old record of the student. (please note that position of a student record in the database file does not matter, after editing you can save it anywhere in the file but the record should be only once in the database file) remove_student [1.5 marks] This function, as the name suggests, is used to remove a student record from the “student.dat” database. 1. It starts by asking the id of the student record you want to remove. 2. Following, it should check if the id exists in the database. 3. In case it does, your script should confirm with the user if he/she wants to delete the student from the database. 4. In case the user confirms the removal, this function should delete the entire line containing the student information. Note that your students.dat file should have no blank line[s]. get_info [1.5 marks] This function, as the name suggests, is used to get information about a particular student. 1. It starts by asking for the id you want to get information about. 2. Then, it should check if the student exists or not. 3. In case the id does not match any student record in the database, it should ask for a new id, or ask if the user wants to go back to the main menu (i.e. the menu function call at the beginning of the loop) 4. It should print all information about the student in a proper format. For example, in the case of 1234, you should print something like: ID: 1234 Name: Anne Shirley Semester: 2 Year: 1 Number of Courses: 5 Proper Scripting Guidelines [2.0 marks] In order to get all 2.0 marks assigned to the quality of your functions, you should follow these guidelines: · Proper indentation. · Use meaningful variable names. For example, if your variable stores id of a student record, you should probably called it student_id or sid. · Proper comments. Whenever you use complex logic, explain what they achieve. You do not need to explain lines of code that are obvious. · Your code should work with any student record information stored in the database, not only the original ones, but also the ones that can be added to it. · Conciseness. There are normally multiple ways to achieve the same result. However, if you are using 20 lines of code to do something that could be done in one or two, you are not doing it right. · More regarding conciseness, you should always create auxiliary functions to perform tasks that are used at multiple points in your script, as opposed to copying and pasting multiple lines of code. For example, if five or more lines of code are used at both remove_student and edit_student, you should consider creating a function, and then call this function from inside these two functions. Example: Adding new student record screen may look like this (in bold are user entered values, however in actual run they will not be bold): ******************************************************** ** Welcome to our students’ database system **Please choose one of the options below: **[a] to add new student record **[e] to edit an existing student record **[i] to get information about a student record **[r] to remove an existing student record **[q] to quit ******************************************************** Your choice: a Please enter student Id: 002 Please enter student name: Anne Shirley Please enter student semester: 2 Please enter student Year: 1 Please enter number of courses student is taking this semester: 4 Record added successfully! ******************************************************** ** Welcome to our students’ database system **Please choose one of the options below: **[a] to add new student record **[e] to edit and existing student record **[i] to get information about a student record **[r] to remove an existing student record **[q] to quit ******************************************************** Your choice: e Please enter student Id: 004 This id does not exist. Press [n] to try a new id or [m] for main menu: n Please enter student Id: 002 The following is the student information: Name: Anne Shirley ID: 1234 Semester: 2 Year: 1 Number of Courses: 5 Which field do you want to edit? [S] for Semester or [Y] Year or [C] for number of courses: C Enter the number of courses: 4 Record updated successfully! part 2 Question 1: Sets and Dictionaries Usage [2.0 marks] a. A company keeps a collection of web sites that are blocked for the employees. A python application that is responsible for this must use which of the following data structures? Explain/Justify your answer to part [1.0 marks] 3. a list 4. a set 5. a dictionary b. An online retail uses a python code to keep track of its customers' orders. Should that collection be kept in a list, set or a dictionary? Justify your answer [1.0 marks] Question 2: Working with sets [7.0 marks] a. Write a code that create three sets as it follows: · s3 which contains numbers between 0 and 500 which are divisible by 3. · s5 which contains numbers between 0 and 500 which are divisible by 5. · s7 which contains numbers between 0 and 500 which are divisible by 7. · s21 which contains numbers between 0 and 500 which are divisible by 11. [2.0 marks] In [ ]: #Your Code Here... b. Write a code that, a. Creates a new set of all elements that are in set3 or set5, but not both. [1.0 marks] b. Creates a new set of all elements that are in only one of the four sets s3, s5, s7 and s11. [2.0 marks] c. Create a new set of all elements that are in exactly two of the sets s3, s5, s7, and s11. [2.0 marks] In [
Nov 17, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here