Question

3. Write a function that makes the following calculation: param1 * param2 / param3 * param4...

3. Write a function that makes the following calculation: param1 * param2 / param3 * param4 / param5...and keeps with this pattern. If any non-numerical character is encountered, 1⁄4 of its value is computed as the numerical value. The result should truncate precision. E.G. function(11,’a’,2,30,’z’,3) returns 393 11 * (97/4) / 2 * 30 / (122/4) * 3

Also no built in functions allowed

DONT USE THIS FUNCTION PLEASE: function expression(param1, param2, param3, param4, param5) { if (param1 !== parseInt(param1)) param1 = param1.charCodeAt(0) / 4; if (param2 !== parseInt(param2)) param2 = param2.charCodeAt(0) / 4; if (param3 !== parseInt(param3)) param3 = param3.charCodeAt(0) / 4; if (param4 !== parseInt(param4)) param4 = param4.charCodeAt(0) / 4; if (param5 !== parseInt(param5)) param5 = param5.charCodeAt(0) / 4; return Math.floor(param1 * param2 / param3 * param4 / param5); }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import math

def function(arr):

ans = int(arr[0])

for index in range(1,len(arr)):

if type(arr[index]) is int:

x = arr[index]

else:

x = ord(arr[index])

if index%2 == 1:

ans = ans * x

else:

ans = ans / x

return math.floor(ans)

def main():

ans = function([11,"a",2,30,"z",3])

print(ans)

main()

Output:

____________________________
Comment down for any queries

Please give a thumb up

Add a comment
Know the answer?
Add Answer to:
3. Write a function that makes the following calculation: param1 * param2 / param3 * param4...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all...

    Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...

  • Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all...

    Using PHP: Write a function that: Given a numerical parameter in input, computes and prints all the prime numbers up to that value. Example: If input parameter is 10, output is "2, 3, 5, 7" If input parameter is 100, output is "2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97" Write a "tester function" that: Given a specific subset of inputs, tests the...

  • Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You...

    Python 3: Please follow the respective rubric for the following function definition. Rubric: Rectangle Shape You should implement the following functions to print a rectangle shape. • print_rectangle(length, width, fillChar, hollow). This function will use draw_shape_line() function to print a rectangle shape with the given length and width, If the hollow is true, the shape will be hollow rectangle, otherwise a filled rectangle. This function must not interact with the user. For example, the call print_rectangle(5, 10, '*', False) should...

  • I'm learning how to write loops in Python 3+ but need help in solving this function...

    I'm learning how to write loops in Python 3+ but need help in solving this function with another function: def babylonian_square_root(N, estimate, precision): new_estimate = (estimate + (N / estimate)) / 2 # I need to complete this using this function close_enough(). def close_enough(x, y, maximum_allowable_difference): ''' Returns True if x and y are within maximum_allowable_difference of each other. ''' # Note: "maximum" implies that we should use <= , but for this to work mathematically we need to use...

  • Write a javascript function that accepts 3 arrays and returns a string of the elements sorted...

    Write a javascript function that accepts 3 arrays and returns a string of the elements sorted in ascending value, with duplicates removed. Return all alphabetic characters in lowercase. E.G. function([ 1,2,3, d], [5, 3, 0, ‘a’], [‘a’,’d’,9]) returns “0,1,2,3,5,9,a,d” E.G. function(['w', 'i', 'H', 5], [8, 5, 9, 'c', 'Z'], [6, 4, 'a', 'b', 'y']) returns “4,5,6,8,9,a,b,c,h,i,w,y,z” we must not use ' sort, remove, split,join and any built-in fucntions

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • 3. Write a function that displays the following table... 4. 6 7 8 9 10 11...

    3. Write a function that displays the following table... 4. 6 7 8 9 10 11 12 13 14 15 4. Write a function that displays output according to this table. Pass in a floating point value, assumed to be a star rating. Use decisions. Consider using a switch if you have no experience with switches! ating 0 0-2.5 2.5-4 4-5 Mes Terrible Not Great Alright 3 Netflix Assignment 3- ICS 225-02 Web x n.minnstate.edu/d2/le/content/4210617/viewContent/36118253/Niew + Assignment #3 JavaScript Problems....

  • matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT