What will be the output of the following Python code?
def foo(k): k[0] = 1 q = [0] foo(q) print(q)
def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])
def foo(): return total + 1 total = 0 print(foo())
def foo(): total += 1 return total total = 0 print(foo())
def foo(x): x = ['def', 'abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
def foo(i, x=[]): x.append(i) return x for i in range(3): print(foo(i))
def foo(k): k = [1] q = [0] foo(q) print(q)
def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc', 'def'] print(id(q) == foo(q))
def foo(i, x=[]): x.append(x.append(i)) return x for i in range(3): y = foo(i) print(y)
def f1(): x=15 print(x) x=12 f1()
def f1(): x=100 print(x) x=+1 f1()
def san(x): print(x+1) x=-2 x=4 san(12)
def f1(): global x x+=1 print(x) x=12 print("x")
def f1(x): global x x+=1 print(x) f1(15) print("hello")
def f1(a,b=[]): b.append(a) return b print(f1(2,[3,4]))
def f(p, q, r): global s p = 10 q = 20 r = 30 s = 40 print(p,q,r,s) p,q,r,s = 1,2,3,4 f(5,10,15)
x = 5 def f1(): global x x = 4 def f2(a,b): global x return a+b+x f1() total = f2(1,2) print(total)
x=100 def f1(): global x x=90 def f2(): global x x=80 print(x)
Read the following Python code carefully and point out the global variables?
y, z = 1, 2 def f(): global x x = y+z
x=1 def cg(): global x x=x+1 cg() x
a=10 globals()['a']=25 print(a)
def f(): x=4 x=1 f() x
Fill in the line of the following Python code for calculating the factorial of a number.
def fact(num): if num == 0: return 1 else: return _____________________
def test(i,j): if(i==0): return j else: return test(i-1,i+j) print(test(4,7))
l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")
Observe the following Python code?
def a(n): if n == 0: return 0 else: return n*a(n - 1) def b(n, tot): if n == 0: return tot else: return b(n-2, tot-2)
def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))
def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")
import datetime d=datetime.date(2017,6,18) print(d)
What will be the output of the following Python code if the system date is 18th August, 2016?
import datetime d=datetime.date.today() print(d.month)
What will be the output of the following Python code if the system date is 18th June, 2017 (Sunday)?
import datetime tday=datetime.date.today() print(tday)
import datetime tday=datetime.date.today() print(tday.weekday())
What will be the output of the following Python code if the system date is 21st June, 2017 (Wednesday)?
import datetime tday=datetime.date.today() print(tday.isoweekday())
What will be the output of the following Python code if the system date is: 6/19/2017
import datetime tday=datetime.date.today() tdelta=datetime.timedelta(days=10) print(tday+tdelta)
import time print(time.asctime())
What will be the output of the following Python function, assuming that the random module has already been imported?
import random random.uniform(3,4)
What will be the output of the following Python function if the random module has already been imported?
import random print(random.randint(3.5,7))
import random print(random.randrange(0,91,5))
Which can be the output of the following Python code?
import random print(random.randrange(1,100,10))