Assignment 3(1)

docx

School

University of Texas, Dallas *

*We aren’t endorsed by this school

Course

4381

Subject

Computer Science

Date

May 5, 2024

Type

docx

Pages

7

Uploaded by AmbassadorMonkeyPerson711

Report
ITSS 4381.001 Spring 2024 – Assignment 3 Part 1 – Multiple Choice [40 Points] Each question is 5 points. Highlight your answer. 1. What happens when you add a key that already exists to a Python dictionary? A) A duplicate key-value pair is created, allowing multiple values for the same key. B) Python raises a KeyError, indicating that duplicate keys are not allowed. C) The value associated with the existing key is updated to the new value. D) The dictionary remains unchanged, ignoring the new key-value pair. 2. Which method allows you to safely remove a key from a dictionary and specify a default return value if the key does not exist, thereby avoiding a KeyError ? A) pop() B) del() C) popitem() D) remove() 3. What is a key characteristic that distinguishes tuples from lists in Python? A) Tuples can contain elements of different types, while lists cannot. B) Tuples are immutable, meaning once a tuple is created, its contents cannot be changed. C) Tuples are used exclusively for numerical data, while lists can contain any type of data. D) Tuples do not support indexing and slicing operations, unlike lists.
4. When using the open() function in Python to perform file operations, which of the following is the recommended way to handle exceptions, such as attempting to open a file that does not exist? A) Use a conditional statement to check if the file exists before attempting to open it. B) Utilize a try-except block, catching the FileNotFoundErro r exception to handle cases where the file does not exist. C) Ignore error handling; Python automatically creates the file if it does not exist, regardless of the operation. D) Call the os.exit() function if a FileNotFoundError is encountered to gracefully exit the program. 5. Which of the following best describes the role of the self parameter in the __init__ method of a Python class? A) It refers to the class itself and is used to define class variables. B) It is a placeholder for future arguments that might be passed to the method. C) It represents the instance of the class and is used to access attributes and methods. D) It specifies that the method should be automatically called when the class is first defined. 6. When creating a child class in Python, what is the correct way to call a method from the parent class within the child class ? A) Use the super() function followed by the method name to call the parent class's method. B) Use the method directly as if it were defined within the subclass itself. C) Prefix the method name with the parent class's name followed by a dot (.) operator. D) It's not possible to call a method from the parent class within the subclass; methods must be redefined.
7. In Python, how does method overriding work when dealing with inheritance? A) By declaring a method in the subclass with a different name but the same functionality as the one in the parent class. B) By defining a method in the subclass that has the same name as a method in the parent class, thus replacing the parent class's method when called on an instance of the subclass. C) By using the override keyword before a method in the subclass to explicitly indicate that it should replace a parent class method. D) Method overriding is not supported in Python; each subclass method must have a unique name. 8. Why is data normalization considered an important step in data preprocessing before applying machine learning algorithms? A) It converts all data to binary format, making it easier for algorithms to process the data. B) It reduces the data to a simpler form where all features contribute equally, preventing biases in the machine learning model. C) Normalization applies different scaling factors to each feature to enhance their original variance, making them more distinct. D) It ensures that all data points are limited to a specific range, such as 0 to 1, which helps in speeding up calculations and improving algorithm performance.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Part 2 – Programming [60 + 10 Points] Please either write your code below each question or take a screenshot of your code. Read the questions carefully. Be mindful of the syntax and all the indent in your code. Make sure your code is runnable and your outputs match the sample outputs. Each question is 30 points. 1. Create a Python application that models a basic school system. The system should include two types of people: students and teachers . Each person should have a name and age stored in a dictionary as their attributes, e.g. {“name”: name, “age”: age}. Teachers have an additional attribute, the subject they teach, while students have a list of grades . Use inheritance to avoid code duplication. In your program, you should have three classes [10 points for each class]: a. Person Class : Create a base class called Person that initializes with a name and age . Store the attributes in a dictionary within the class. Implement a method get_details() that returns the person's details as a string. b. Student Class : Create a Student class that inherits from Person . Add an attribute called grades for storing a list of grades (e.g., [90, 80, 85]) in the initializer. This should also be stored together with the name and the age in the attributes dictionary. Implement a method calculate_average_grade() that calculates and returns the student's average grade. Override the get_details() method to include average grade information in the returned string. c. Teacher Class : Create a Teacher class that inherits from Person. Add an attribute called subject for storing the subject they teach in the initializer. This should also be stored together with the name and the age in the attributes dictionary.
Override the get_details() method to include the subject information in the returned string. In your main program: Instantiate a few Student and Teacher objects with various details. Call the get_details() method on each instance and print the results to demonstrate that your system works. Samples for your main program and the outputs:
2. Download the dataset StudentsPerformance.csv from eLearning. Write codes that perform the following: Read the dataset and have a preview of the dataset. [4 points] Replace all the missing values (which are represented as “Null”) with the mean of its column. [Hint: you need to replace “Null” with np.NaN first so that you can change the data type and then calculate the mean.] Show that the dataset has no missing value after this step using isnull().sum() . [12 points] Correct the data types (you should have done it from the last step). Compute the average of “math score”, “reading score” and “writing score” for each row and add it as a new column named “average score” to the dataset. [5 points] Create dummy variables for all the columns with categorical values (you can either keep the original columns or drop them). [5 points] Save the cleaned dataset to your computer and name it StudentsPerformance_cleaned.csv . [4 points] Your dataset should look like the below after all the steps (some columns are omitted):
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Bonus : compute two different types of graphs that show some meaningful information from the cleaned dataset and briefly explain what each of your graphs shows. [10 points] [Hint: You can either follow the code from our class to create the graphs (e.g., line plot, scatter plot, box plot, etc.) or go to matplotlib ’s examples , choose the type of graphs you want to create and modify the codes accordingly.]