IIT KHARAGPUR AI4ICPS I HUB FOUNDATION
Hands-on Approach to AI, Cohort-4, November 2025 - January 2026
Programming Assignment 2
Objective:
The objective of this assignment is to create a Python program using NumPy that performs
different mathematical computations based on an input value. This will test your
understanding of NumPy functions, and conditional logic in Python.
Problem Statement:
Write a Python program that performs advanced mathematical computations based on an
input value (x).
1. Students should only modify the function advanced numpy calculator(x) to
implement the computations.
2. Do not modify anything in the main section or the rest of the code.
3. The function advanced numpy calculator(x) should return the output correspond ing
to the input x rounded to four decimal places.
4. All output values should be rounded to four decimal places.
5. Submit your solution in a file named [Link].
Mathematical Operations:
Input Range (x) Operation Description NumPy Functions
x<0 Exponential Decay Compute ex [Link](x)
0 ≤ x < 10 Trigonometric Compute [Link](), [Link](),
Transformation sin(x) + cos(2x) [Link]()
(convert degrees to
radians)
10 ≤ x < 50 Logarithmic Compute np.log1p(x),
Scaling [Link](x)
log(1 + x) × √x
50 ≤ x < 100 Matrix Determinant of [Link](),
Determinant [[x, x/2], [x/3, x/4]] [Link]()
x ≥ 100 Polynomial Evaluate x3 − 2x2 + 3x − 4 [Link](coeffs,
Evaluation x)
Test Cases:
Test Case Input (x) Expected Operation Expected Output
1 -5 Exponential decay 0.0067
2 -0.1 Exponential decay 0.9048
3 3 Trigonometric transformation 1.0469
4 15 Logarithmic scaling 10.7382
5 30.25 Logarithmic scaling 18.9311
6 55 Matrix determinant 252.0833
7 100 Polynomial evaluation 980296.0000
Skeleton Code:
Students are required to modify the following Python code:
# [Link]
import sys
import numpy as np
def advanced_numpy_calculator ( x ) :
"""
Perform a mathematical calculation based on the value of x. To be implemented by the
student .
"""
# TODO : Implement the logic based on x
# Hint : Use conditional statements to handle different ranges of x
# Use NumPy functions for calculations
pass
def main () :
if len ( sys . argv ) != 2:
print (" Usage : python assignment2 .py <number >")
sys . exit (1)
try :
x = float ( sys . argv [1])
except ValueError :
print (" Please enter a valid number .")
sys . exit (1)
result = advanced_numpy_calculator ( x )
print ( f" Output : { result :.4 f}\n")
if __name__ == " __main__ ":
main ()
Instructions for Students:
1. Modify the advanced numpy calculator(x) function to handle all 7 operations.
2. Use NumPy functions wherever possible.
3. You can run the program from the command line to check if it performs correctly:
python [Link] 25