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()
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()
Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...
in pyton Looking at the following function definition: def my_function(a,b,c): d = (a + c) / b print(d) return Write a statement which calls this function using KEYWORD ARGUMENTS to pass 2 into a, 4 into b and 6 into c.
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 * 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, 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
##8. 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 assigns its return value ##to the variable result. ##9. Write a function named times_ten that accepts a number as an argument. When the ##function is called, it should return the value of its argument multiplied times 10. ##10. Write a function named is_valid_length that accepts a string and an integer as ##arguments....
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] 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)”, 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 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:...
Python Program Only: Write the function definition only of the "get(self, index)" function. Plug your method in the code file shared with you and test it in the main to get the element at index 3 of mylist2 . class Node: def __init__(self, e): self.element = e self.next = None class LinkedList: def __init__(self): self.head = None self.tail = None self.size = 0 def addFirst(self, e): newNode = Node(e) newNode.next = self.head self.head = newNode self.size = self.size + 1...