Question

Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...

Look at the following function definition:
def my_function(x, y):
return x[y]
a. Write a statement that calls this function and uses keyword arguments to pass
‘testing’ into x and 2 into y.
b. What will be printed when the function call executes?
6. Write a statement that generates a random number in the range

I'm using python to solve this

this is what i did

def main():

     result= my_function(x='testing', y=2)

     print(result)

def my_function(x,y):

     return x[y]

main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def main():
    # a. Write a statement that calls this function and uses keyword arguments to pass 'testing' into x and 2 into y.
    result = my_function(x='testing', y=2)

    # b. What will be printed when the function call executes?
    print(result)

    # 6. Write a statement that generates a random number in the range 10 to 100
    from random import randint
    print(randint(10, 100))


def my_function(x, y):
    return x[y]


main()
Add a comment
Know the answer?
Add Answer to:
Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...
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
  • In the following function definition, what do we call ans? def show_cube_root(x):        ans = x...

    In the following function definition, what do we call ans? def show_cube_root(x):        ans = x ** (1.0/3.0)        print('The cube root of ' + format(x, '.3f') + ' is ' \                + format(ans, '.3f') + '.') a global variable a local variable a parameter a keyword

  • in python 3 1. A program contains the following function definition: def cube(num): return num *...

    in python 3 1. A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the value 4 to this function and assign its return value to the variable result. 2. Write a function named get_first_name that asks the user to enter his or her first name and returns it.

  • def max_of_two( x, y): ifx>y: return x returny a. Write a Python function called max_of_three( x,...

    def max_of_two( x, y): ifx>y: return x returny a. Write a Python function called max_of_three( x, y, z ) to return the largest numbers of three numbers passing to the function You can use the function max_of_two in your solution. /Your code

  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • Consider the following Python program: def fun(x, y): return x + y # [2] # [1]...

    Consider the following Python program: def fun(x, y): return x + y # [2] # [1] a = fun(2, 3) b = fun("2", 3) print a, b What does it evaluate to? Replace the last statement print a, b with print a + b and explain the traceback. What's wrong? Now eliminate the line marked [1] and change line [2] to read return x + y. Run the program and explain the traceback. Consider the following definition: def fun(n, m):...

  • Write a program that contains a main function, a “double custom_operator_function(int op_type, double x, double y)”,...

    Write a program that contains a main function, a “double custom_operator_function(int op_type, double x, double y)”, a “double min(double,double)”, a double max(double x,double y), and a double pow(double x, int y). The main function is used to call the custom operator function. Next, the custom operator function calls the min/max/pow functions based on the op_type. From the main, call the custom operator function with the three inputs 1/-3/5, 2/4/5, and 3/4/5. Print the result of each input to screen. i)...

  • How to write python code that is a dice rolling function that generates random numbers. The...

    How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...

  • Which of the following will result in an output of: 8 def pass_it(x, y): z =...

    Which of the following will result in an output of: 8 def pass_it(x, y): z = x**y return(z) num1 = 2 num2 = 3 answer = pass_it(numi, num2) print(answer) def pass_it(x, y): z = y*** return(z) num1 = 2 num2 = 3 answer = pass it(numl, num2) print(answer) def pass_it(x, y): 22*3 return(z) num1 = 2 num23 answer pass_it (numi, num2) print(answer) def pass_it(x, y): Z = xy return(2) num1 = 2 num23 answer = passit(numl, num2) print(answer) # Hint...

  • Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as...

    Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...

  • Write a function in python that takes a set A and a relation R(x, y) on...

    Write a function in python that takes a set A and a relation R(x, y) on A (as a python function such that R(x, y) returns true if and only if the relation xRy holds), and returns True if and only if the relation R is reflexive. Here is the function signature you need to use. def is reflexive(A, R): You can test your code as follows. s = {1,2,3} def y(x, y): return x == y def n(x, y):...

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
ADVERTISEMENT