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 |
Answer:-
15
Explanation:-
a = bar() + 2 // it will return 5 b = baz(a, 2) // it will return 10 foo(a + b) //then it will print a+b=15
Consider the following small program. What will the output be? def foo(x): print(x) def bar(): return...
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
Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...
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):...
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...
5. What is the output of the below program? (14 marks) def Fungsi (xx): print ("x is ", xx) values=[8 ,2 , 6 , 6 ,2 ,6) c=0 for i in range (len (values)): if (values[i] == xx): C=C+1 if c> 0 : print ("Return ", c) return c else: C = 100 print ("Return ", c) return c A = Fungsi (2) print ("The A is ", A) B= Fungsi (6) + Fungsi (7) print ("The Bis", B)
Question 6 (1 point) Consider the following piece of code. What will the output be of this code? int foo() { int fun = 0; int bar (int fun) { fun = fun - 1; return fun 1; } return fun + bar (fun + 1); } print (foo ()); print (foo ()); -1 2 1 0
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
2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?
#Which function has the most parameters? def Menu(): print ("Your Name Main Menu") print("1. Sum") print("2. Product") print("3. information") print("4. Quit") def Sum(x): x= x* 2 y = 10 answer = x+y return x,y,answer def Product(w,z): answer = w*z print (answer) def Calc(a,b,c): return a*b*c Question options: Product Calc Menu Sum
12. What is the output of this program? Your answer: 1 def main(): 2 print('The numbers are:') 3 for i in range (2,25): 4 isone (i) 5 def isone (number): isOne = True i = 2 while i < number and is one: if number % i == 0: 10 isOne = False 11 i += 1 Lou if isOne == True: 13 print("\t', i) 14 main() 12 13. What is the output of this program? Your answer: for i...