Using Python: 1. Write a function that takes as a parameter a list of numbers an
ID: 3836339 • Letter: U
Question
Using Python:
1. Write a function that takes as a parameter a list of numbers and returns a list containing each number squared. That is, if the input parameter is [3,-1,0,2,10], your function should return [9,1,0,4,100]. The file you submit should include a main() function that demonstrates that your function works.
2. Define a Python function named calculate_tax() which accepts one parameter, income, and returns the income tax. Income is taxed according to the following rule: the first $250,000 is taxed at 40% and any remaining income is taxed at 80%. For example, calculate_tax(100000) should return $100,000 * 0.40 =$40,000, while calculate_tax(300000) should return $250,000 * 0.40 + 50,000 * 0.80 = $140,000.
In your file, you should include a main() that calls your function several times to demonstrate that it works.
Explanation / Answer
1.
def square(arr):
return map(lambda x: x ** 2, arr)
A = raw_input("Enter list:")
A = map(int, A.split())
print square(A)
2.
import sys
class IncomeTax:
def calculate_tax(self,income):
print income #int(income)
if income <= 250000:
return float(income*.40)
else:
return float(250000*.40+(income-250000)*.8)
if __name__ == "__main__":
incomes = sys.argv[1:]
for income in incomes:
print IncomeTax().calculate_tax(int(income))
to run this save this file with .py extension and run command python file.py income1 income2 and so on
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.