What will be the output of the following Python code?
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)
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())
Which of the following will throw an error if used after the following Python code?
bday=datetime.date(2017,9,18)
t_day=bday-tday
What will be the output of the following Python code if the system date is: 6/19/2017
tdelta=datetime.timedelta(days=10)
print(tday+tdelta)
import time
time.time()
time.asctime()
t=(2010, 9, 20, 8, 15, 12, 6)
time.asctime(t)
t=(2010, 9, 20, 8, 45, 12, 6, 0, 0)
import random
random.choice(2,3,4)
random.choice([10.4, 56.99, 76])
What will be the output of the following Python function (random module has already been imported)?
random.choice('sun')
What will be the output of the following Python function, assuming that the random module has already been imported?
random.uniform(3,4)
What will be the output of the following Python function if the random module has already been imported?
random.randint(3.5,7)
random.seed(3) random.randint(1,5) 2 random.seed(3) random.randint(1,5)
random.randrange(0,91,5)
random.randrange(1,100,10)
What will be the output of the following Python function, assuming that the random library has already been included?
random.shuffle[1,2,24]
What will be the output of the following Python code, if the code is run on Windows operating system?
import sys
if sys.platform[:2]== 'wi':
print("Hello")
What will be the output of the following Python code, if the sys module has already been imported?
sys.stdout.write("hello world")
eval(sys.stdin.readline())
"India"
Computer
sys.argv[0]
sys.stderr.write(“hello”)
What will be the output of the following Python code
sys.argv