Question
1. Create a module called 'funct' that contains the following functions. (CODE IS SHOWN BELOW FOR THIS) def total(val) - returns sum of all #
1. Create a module called 'funct' that contains the following functions. (CODE IS SHOWN BELOW FOR THIS)
def total(val) - returns sum of all # in the list 'val'.
def sub(val) - returns the difference of all # in the list 'val'.
def times(val) - returns the product of all # in the list 'val'.
def div(val) - returns the result of dividing all # in the list 'val'. If first # is 0, then the result is 0. If any other # are 0, use sys.exit to stop it & display 'invalid list.'
2. Use main.py to validate the arguments via terminal. (NEED TO COMPLETE THIS PART)
a. If length <=1, use sys.exit to display the message 'Please input operator name.'
b. If length <=3, use sys.exit to display the message 'Please input 2 or more values.'
c. If length >3, retrieve the operator name and values. Save them as floats into a list when given from the terminal. Assume all values are digits.
d. Call funct.py to perform operations. Use 2 decimal places.
SAMPLE OUTPUT
C:\User\Documents python main.py
Please input operator name.
C:\User\Documents python main.py total
Please input 2 or more values.
C:\User\Documents python main.py times 2 3 6
Ans = 36.00
C:\User\Documents python main.py div 0 3 6
Ans = 0.00
C:\User\Documents python main.py div 3 0 6
Invalid list.
C:\User\Documents python main.py sub 10 4 2
Ans = 4.00
C:\User\Documents python main.py algebra
Not a valid operator.
MY funct.py CODE
import sys def total(val): sum = 0 for i in val: sum = sum + i return sum
def sub(val): diff = 0 for i in val: diff = diff - i return diff
def times(val): prod = 1 for i in val: prod = prod * i return prod
def div(val): quot = val[0] val.pop(0) if quot == 0: return 0 for i in val: if i == 0: sys.exit('invalid list') else: quot = quot / i return quot
#def main(): # val = [1,2,3,4,5] # print('Sum: ', total(val)) # print('Difference: ', sub(val)) # print('Product: ', times(val)) # print('Quotient: ', div(val))
#if __name__ == '__main__': # main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started