0% found this document useful (0 votes)
11 views2 pages

FOOD 101 _ Assignment 0

Uploaded by

pankajpandhawale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

FOOD 101 _ Assignment 0

Uploaded by

pankajpandhawale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

FOOD 101 : Assignment for Week 0 :

Question 1: Function to Calculate the Slope of a Cubic Polynomial


Write a Python function named slope_of_cubic that calculates the slope of a cubic polynomial
based on user input. The function should:

1. Accepts two arguments:


● A tuple containing 4 real numbers which are the coefficients of the cubic term,
quadratic term, linear term, and constant term respectively.
● A real number which is the value of x at which the slope has to be calculated.
2. Returns the slope of the cubic polynomial at the given value of x.

Deliverable: Submit a .py file named cubic_slope.py.

Question 2: Matrix Operations


Write a Python function named matrix_operation that performs various matrix operations based
on user input. The function should:

1. Accept three arguments:


○ Two 2D NumPy arrays (array1 and array2).
○ A string (operation) that specifies the operation to be performed.
2. Perform the following operations based on the value of operation:
○ If operation is "dot", compute the dot product of array1 and array2.
○ If operation is "matrix", perform matrix multiplication of array1 and array2.
○ If operation is "determinant", return a tuple containing the determinants of array1 and
array2. Handle cases where determinants cannot be computed (e.g., non-square
matrices) by returning an appropriate error message.
Deliverable: Submit a .py file named matrix_operations.py.

Question 3: Handling Missing Data in a CSV File


You are provided with a CSV file named IITK_Courses_Report.csv that contains four columns:
two non-numerical and two numerical. Write a Python program using Jupyter Notebook (or
Google Collab) to perform the following operations:

1. Load the CSV file into a Pandas DataFrame.


2. Check for null values in all columns.
3. For rows where either of the non-numerical columns contain null values, delete the entire
row.
4. For numerical columns, replace each null value with the geometric mean of the values in
the rows immediately above and below the null value.
5. Save the cleaned DataFrame back to a new CSV file named
cleaned_IITK_Courses_Report.csv.
Link to download the CSV File :
https://drive.google.com/file/d/1QFJGdkhJClgTLr0u29WHF7yUuauw_z3A/view?usp=sharing

Deliverable: Submit a .ipynb file named handle_missing_data.ipynb.

Optional Question : Using the Pickle Module


Just for Practice, You don’t have to submit :)

Write a Python program that demonstrates the usage of the pickle module by performing the
following operations:

1. Create a dictionary where the keys are the names of fruits, and the values are their prices
(e.g., {"apple": 100, "banana": 40}).
2. Save this dictionary to a binary file using the pickle module.
3. Read the dictionary back from the binary file and display its contents.
4. Update the price of a specific fruit by:
○ Prompting the user to enter the fruit's name and the new price.
○ Checking if the fruit exists in the dictionary.
○ If the fruit exists, update its price and save the updated dictionary back to the binary file.
○ If the fruit does not exist, inform the user.
5. Read and display the updated dictionary from the binary file.

Optional Question : Counting Unique Words in a String


Just for Practice, You don’t have to submit :)

Given a string str1 that contains words separated by spaces without any punctuation, complete
the function num_unique_words to return the number of unique words in the string.

● You are not allowed to use any external libraries; only Python built-in functions should be
used.
● Think carefully about how you can achieve this using basic Python operations/functions.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy