0% found this document useful (0 votes)
15 views22 pages

Python

Uploaded by

HT DH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views22 pages

Python

Uploaded by

HT DH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

def fun(inp=2, out=3):

return inp * out

print(fun(out=2))

DA: 4

a=1

b=0

a =a^b

b = a^b

a=a^b

print(a,b)

DA: 0 1

Which of following lines incorrectly invokes the function defined as:

def fun(a,b,c=0):

DA: fun(a=1 b=0 c=0)

def fun(x,y):

if x==y:

return x

else:

return fun(x,y-1)

print(fun(0,3))

DA: 0
def func1(a):

return None

def func2(a):

return func1(a) * func1(a)

print(func2(2))

DA: error

an operator able to check whether two values are not equal is code as

DA: !=

lst =[i for i in range(-1,-2)]

x=float(input())

y=float(input())

print(y**(1/x))

DA: 2.0

x= int(input())

y= int(input())

x=x%y

x=x%y

y=y%x

print(y)
DA: 0

dct={}

dct['1']=(1,2)

dct['2']=(2,1)

for x in dct.keys():

print(dct[x][1],end="")

DA: 12

lst=[1,2]

for v in range(2):

lst.insert(-1,lst[v])

print(lst)

DA: [1,1,1,2]

def func(a,b):

return b**a

print(func(b=2,2))

DA: error

i=0

while i<i+2:

i+=1

print("*")

else:
print("*")

DA: loop, printing one star per line

1//2

DA: cannot be predicted

y= input()

x= input()

print(x+y)

DA: 63

nums =[1,2,3]

vals=nums

DA: nums and vals are different names of the same list

x=1//5 + 1/5

print(x)

DA: 0.2

dct={'one':'two','three':'one','two':'three'}

v=dct['three']

for k in range(len(dct)):

v=dct[v]

print(v)

DA: one
x= 1

y=2

x,y,z = x,x,y

z,y,z = x,y,z

print(x,y,z)

DA: 1 2 2

list = [x*x for x in range(5)]

def fun(lst):

del lst[lst[2]]

return lst

print(fun(list))

DA: 0 1 4 9

tup = (1,2,4,8)

tup = tup[-2:-1]

tup = tup[-1]

print(tup)

DA: 4

print("a","b","c",sep="sep")

DA: a sep b sep c

def fun(x):
if x % 2 == 0

return 1

else:

retrun 2

print(fun(fun(2)))

DA: error

lst = [[x for x in range(3)] for y in range(3)]

for r in range(3):

for c in range(3):

if lst[r][c] % 2 != 0:

print("#")

DA: three

dd = {"1":"0", "0":"1"}

for x in dd.vals():

print(x,end="")

DA: the codeis error

nums = [1,2,3]

vals = nums

del vals[:]

DA: num va val se khac list


The meaning of a positinal argument: its position..

One of the following variable..: in

Tuple[1]=tuple[1]+tuple[0]: Is illigal

Import math

Print(dir(math))

DA: A list…

Print(float(“1.3”)

DA: 1.3

For x in open(‘file’,’rt’):

Print(x)

DA: read the file line by line

Clas A:

DA: attributerror
From mode import fun

DA: fun()

Class A:

Pass

Class B(A)

DA: FALSE

#FILE A.PY

DA: cab

Try:

Raise Exception

DA: errror

Print(chr(ord(‘p’)+2))

DA: r

If you want to fill:

DA: readinto()

Class Class:

Def_init…
DA: Class(1,2)

Class I:

Del_init

DA: abc

For line in open

Da: open return an iterable object

The complie Python:

Da: pyc

X=”\\\\”

DA: 2

Except: try:

DA: Not more than one

Class A:

Del_int_(self)

Print(hasattr(a,’A’))

DA: it will raise an exception

Class A:

Del a(self)
o.c()

DA: b

Try:

Raise Exception

Excep:

Print(“c”)

DA: a

From a.b import c

DA: c b a

Def I(n)

DA: +

q=s.read(1)

DA: one character from the stream

Try:

Raise Exception(1,2,3)

DA: it will print 3

Class A:

A=1

DA: false
From f import m

DA: Mod:fun()

D={1:0,2:1,3:2,0:1}

X=0

Print(x)

DA: 0

If you want to write:

DA: write()

Ls=[[c for c in range[r]]

Da: Two

Str1=’string’

Str2=str1[:]

DA: Khac ten nhung khong bang string

What is the name pcy file?

DA: pycache

What will module.py?

DA: _main_
y= input()

x= input()

print(x+y)

DA: 21

print("a","b","c",sep="'")

DA: a’b’c

An operator able to check whether two value are equal?

DA: = =

class A:

pass

class B:

pass

class C(A,B):

pass

print(issubclass(C,A) and issubclass(C,B))

DA: True

The package directory/folder?


DA: _init_.py

If you want to tell your module?

DA: _or __

v=1+1//2+1/2+2

print(v)

DA: 3.5

print(len([i for i in range(0,-2)]))

DA: 0

IF s is a stream opened in read mode, the following line?

DA: list

def I(n):

s=''

for i in range(n):

s+='*'

yield s

for x in I(3):

print(x,end='')

DA: ******

str='abcdef'
def fun(s):

del s[2]

return s

print(fun(str))

DA: error

The Exception class contains a property name args:

DA: tuple

class A:

def __init__(self):

pass

def f(self):

return 1

def g():

return self.f()

a=A()

print(a.g())

DA: it will raise an exception

d={'one':1,'three':3,'two':2}

for k in sorted(d.values()):

print(k,end='')

DA: 1 2 3
class A:

def __init_(self,v):

self._a=v+1

a= A(0)

print(a._a)

DA: 1

try:

raise Exception

except:

print("c")

except BaseException:

print("a")

except Exception:

print("b")

DA: it will cause an error

try:

raise Exception

except BaseException:

print("a",end='')

else:

print("b",end='')

finally:

print("c")
DA: ac

def f(par2,par1):

return par2+par1

print(f(par2=1,2))

Da: is Erroneous

print(len(1, )))

DA: 1

The sys.stdout strem is normally associated with:

DA: the screen

class Class:

def __init_(self):

pass

Which one of the assigment is valid?

DA: object = Class()

class A:

def a(self):

print('a')

class B:

def a(self):

print('b')
class C(A,B):

def c(self):

self.a()

o=C()

o.c()

DA: a

Which of following lines incorrectly invokes the function defined as:

def fun(a,b,c=0):

DA: fun(a=1 b=0 c=0)

def fun(d,k,v):

d[k]=v

dc ={}

print(fun(dc,'1','v'))

DA: None

def fun(x):

return 1 if x%2 !=0 else 2

print(fun(fun(1)))

DA: 1

x="\"

print(len(x))
DA: error

class A:

A=1

def __init__(self):

self.a=0

print(hasattr(A,'A'))

DA: True

class A:

A=1

def __init__(self,v=2):

self.v=v+A.A

A.A+=1

def set(self,v):

self.v+=v

A.A+=1

return

a=A()

a.set(2)

print(a.v)

DA: 5

d={1:0,2:1,3:2,0:1}

x=0
for y in range(len(d)):

x=d[x]

print(x)

DA: 0

i=4

while i>0:

i-=2

print("*")

if i ==2:

break

else:

print("*")

DA: one

t=(1, )

t=t[0]+t[0]

print(t)

DA: 2

class X:

pass

class Y(X):

pass

class Z(Y):
pass

x=X()

z=Z()

print(isinstance(x,Z), isinstance(z,X))

DA: false True

lt=[1,2,3,4]

lt= list(map(lambda x: 2*x,1))

print(lt)
DA: 2 4 6 8

d={}

d['2']=[1,2]

d['1']=[3,4]

for x in d.keys():

print(d[x][1],end="")

DA: 42

class A:

def __init__(self,name):

self.name =name

a=A("class")

print(a)

DA: a string ending with a long hexadecimal number


def a(x):

def b():

return x+x

return b

x=a('x')

y=a('')

print(x()+y())

DA: xx

x="""

"""

print(len(x))

DA: 1

x,y,z=3,2,1

z,y,x=x,y,z

print(x,y,z)

DA: 1 2 3

x=16

while x>0:

print('*',end='')

x//=2

DA: *****
a= True

b= False

a= a or b

b= a and b

a = a or b

print(a,b)

DA: True false

You might also like