Here is the explanation of how all the above functions works along with the screenshots of code and output.
1. def fun(X,Y):
return X*Y
a = fun(2,3)
b = fun("2",3)
print(a , b)
Explanation :
SCREENSHOT(CODE AND OUTPUT)
When you run the above code the output looks like below.
1(b) . If we change print(a , b) to print(a + b) , then it will show an error because
The output of fun(2,3) which is in a is of int type ( a = 6) The output of fun("2",3) which is in b is of string type.(b = "222") When we try to print a + b as string cannot be concatenated with int directly it will show an error |
SCREENSHOT
1(c) If we remove a = fun(2,3) and change return X*Y to return X + Y it will also generate an error . To understand this see the below trace back.
SCREENSHOT
2(a) The explanation in the form of stack for 2 (a ) is as follows
For 2(b) & 2(c)
Explanation
SCREENSHOT
For third one the output and explanations are as below.
SCREENSHOT
After changing return Y - X to X - Y
Consider the following Python program: def fun(x, y): return x + y # [2] # [1]...
Hi, Looking for some help with this Python question as follows: Consider the following Python program: def fun(x, y): return x * y a = fun(2, 3) b = fun("2", 3) print(a, b) What does the function evaluate to? What would happen if we replace the last statement print a, b with print a + b? Thanks for any help. John
Consider the following small program. What will the output be? def foo(x): print(x) def bar(): return 3 def baz(y, z): return y * z a = bar() + 2 b = baz(a, 2) foo(a + b) 10 3 2 25 none of these 15
Consider the following small program. What will the output be? def foo(x): return x + 2 x = 1 x = foo(x) print(x) 'x' 3 1 2 none of these
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()
Please help on my homework Q i got wrong: PYTHON Question 1 def higherOrderFilter(data, p) : res = [] for d in data : if p(d) : res.append(d) return res def FilterR(data, p): if data == []: return [] return [data[0]] + FilterR(data[1:], p) if p(data[0]) else FilterR(data[1:], p) Both of these functions produce the same output given the same data and same filtering condition p. True False Question 2...
in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Pop(self): return self.items.pop() def Display(self): for i in reversed(self.items): print(i,end="") print() s = My_Stack() #taking input from user str = input('Enter your string for palindrome checking: ') n= len(str) #Pushing half of the string into stack for i in range(int(n/2)): s.Push(str[i]) print("S",end="") s.Display() s.Display() #for the next half checking the upcoming string...
1. Questions Python Code: For each line of code, write the type of error (syntax, semantics, runt-time), cause of the error, and your fix. (1) def fun(num letter) (2) num == 7 + num (3) return 'num' - letter (4) result = fun(5, x) 2. Question Python Code: Run the code below to check the outputs of the print() call on lines 12. And : A) Analyze the application of the accumulation pattern and answer the following questions: #1. a....
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.
in python, What is the outcome? :x= -1 y= -2 z= -3 def h( x, y=2, z=3); print x,y,z h(1, z=4 )
Consider the following function: def w(x, y) : z = x + y return z What is the function's name? Group of answer choices w x y z