[SOLVED] CSE101 Lab 2 - Functions in python

39.99 $

Category: Tags: ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon CSE101-Lab2-main-r1jvcf.zip (324.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

Functional programming is a programming paradigm where everything is a function

In this lab, we will mimic a functional programming style!
Note: Keep in mind that it’s highly impractical to mimic like this, however the purpose of this exercise is to familiarize yourselves with functions
Of course, we can’t do everything as a function: assignments and function definitions will remain. We will only work on arithmetic operations
Arithmetic operations Example when replacing original operators with functions
To functional

# Python code a = 5
b = (6 + a) / 3 ** 2 print(b)

# Functional variant a = 5
b = div(add(6, a), exp(3, 2)) print(b)

What is the behavior of add(a,b)?
What is the behavior of add() x x+y
• How many inputs? y
# add() def add(a,b) : return a + b
• How many outputs?
• What will be the output?
Task 1
Implement the following functions
Sub() Div() Mult() exp()
Quizzes Quizzes Quizzes Quizzes – / * **
exp(2,4) = 2 * 2 * 2 * 2
Also add neg() and sqrt()
• E.g., neg(5) should return -5, neg(-5) should return 5
• E.g., sqrt(16) should return 4
Follow the comments in “func.py”
Conditions
• Do not import anything
• Do not use any techniques not taught in class yet

Task 2
The next task is to reproduce the result of task 1 of Lab 1 : the quadratic formula
Except this time, use only the six functions above
(variable assignments can be done as usual, of course)
Conditions
• Do not import anything
• No outside function
• No arithmetic operators outside your functions

  • CSE101-Lab2-main-r1jvcf.zip