In: Computer Science
Write an evenTest(n) function that returns True if it is given
an even integer and False if it is given an odd number. The rest of
your code (outside of the function) should get an integer number
from the user, call evenTest(n) to test if the number is even, and
then tell the user if the number was even or odd. Name the program
even_or_odd.py.
Part 2. Salary.py (5 pts) You are offered two options to receive
salary: • Option 1: Constant Salary: Receive $100 each day for 10
days • Option 2: Doubling Salary: $1 the first day, $2 the second
day, $4 the third day, $8 the fourth day, doubling the amount each
day, for 10 days. Define a function constant_salary() that computes
and returns the total income for Option 1. Define a function
doubling_salary() that computes and returns the total income for
Option 2. The rest of your code (outside of the functions) should
call both functions, compare the totals they return, and determine
which salary option pays more. This program does not ask the user
for any input. Name the program salary.py.
/* PLEASE INDENT THE CODE USING SCREENSHOT TO RUN THE CODE WITHOUT ERROR */
Write an evenTest(n) function that returns True if it is given an even integer and False if it is given an odd number. The rest of your code (outside of the function) should get an integer number from the user, call evenTest(n) to test if the number is even, and then tell the user if the number was even or odd. Name the program even_or_odd.py.
Ans. even_or_odd.py
def evenTest(n):
if(n%2==0): # CHECK IF DIVISIBLE BY 2
return True
else:
return False
def main():
n = int(input("Enter an Integer: "))
if(evenTest(n)):
print("{} is even".format(n))
else:
print("{} is odd".format(n))
if __name__ == '__main__':main() # ENTRY POINT OF ALL
CODE
Part 2. Salary.py (5 pts) You are offered two options to receive
salary: • Option 1: Constant Salary: Receive $100 each day for 10
days • Option 2: Doubling Salary: $1 the first day, $2 the second
day, $4 the third day, $8 the fourth day, doubling the amount each
day, for 10 days. Define a function constant_salary() that computes
and returns the total income for Option 1. Define a function
doubling_salary() that computes and returns the total income for
Option 2. The rest of your code (outside of the functions) should
call both functions, compare the totals they return, and determine
which salary option pays more. This program does not ask the user
for any input. Name the program salary.py.
Ans.
def constant_salary():
total = 0
for i in range(1,11): # runs from 1 to 10
total += 100
return total
def doubling_salary():
total = 0
for i in range(0,10): # LOOP RUN FROM 0 TO 9 = 10
total += 2**i # it finds exponent of 2 and add it to total 2**2 = 4
= 2^2 = 4
return total
def main():
totalConst = constant_salary()
totalDoubl = doubling_salary()
if(totalConst > totalDoubl):
print("Option 1 constant_salary pays ${}
more".format(totalConst-totalDoubl))
elif(totalConst < totalDoubl):
print("Option 2 double_salary pays ${} more".format(totalDoubl -
totalConst))
if __name__ == '__main__':main()
/* PLEASE UPVOTE IF ANY DOUBT COMMENT ME IN COMMENT SECTION */