Question

In: Computer Science

Write an evenTest(n) function that returns True if it is given an even integer and False...

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.

Solutions

Expert Solution

/* 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 */


Related Solutions

write the “largerComponents” method that takes in two integer arrays and returns true or false if...
write the “largerComponents” method that takes in two integer arrays and returns true or false if the first array’s components are strictly greater than the second array’s components. The arrays must be the same size or else return false. Clarification Note: Components meaning each value at a specific index. For instance, if we had the arrays {5,2,7} and {1,3,1} then this method would return false as the value “2” is not greater than “3”. here is a provided code //Do...
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them
Write a Scheme function that takes a positive integer n and returns the list of all...
Write a Scheme function that takes a positive integer n and returns the list of all first n positive integers in decreasing order: (decreasing-numbers 10) (10 9 8 7 6 5 4 3 2 1) Please explain every step
Given a positive integer n, write a recursive algorithm that returns the number of the digits...
Given a positive integer n, write a recursive algorithm that returns the number of the digits in n. For example, if the given number n is 12345, the algorithm should return 5. What is the time complexity of your algorithm? use java
Given a positive integer n, write a recursive algorithm that returns the number of the digits...
Given a positive integer n, write a recursive algorithm that returns the number of the digits in n. For example, if the given number n is 12345, the algorithm should return 5. What is the time complexity of your algorithm?
that, given an integer N and an integer K, returns the minimum number of rounds that...
that, given an integer N and an integer K, returns the minimum number of rounds that are necessary for John to leave the casino with N chips, having played all-in no more than K times.
Write a boolean function that is given a binary tree and returns true if and only...
Write a boolean function that is given a binary tree and returns true if and only if the tree has an odd number of nodes. An empty tree is considered to have an even number of nodes. Notes: The function should have just one argument, a pointer to the root. No global variables may be used. No additional functions may be defined. You may not count the number of nodes.
Write a function maxFun() that returns the maximum value in any given integer array. Determine the...
Write a function maxFun() that returns the maximum value in any given integer array. Determine the function parameters (complete the area shown in ___________. ___________maxFun(____________________________) { }
Write a function intLog of type Integer -> Integer that returns the exponent of the largest...
Write a function intLog of type Integer -> Integer that returns the exponent of the largest power of 2 less than its integer argument. This needs to be a haskell function
Prove that if n is an integer and n^2 is even the n is even.
Prove that if n is an integer and n^2 is even the n is even.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT