0% found this document useful (0 votes)
131 views

Python and SQL

This is an sql and python question commonly asked in ikm

Uploaded by

Shaik Sajid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
131 views

Python and SQL

This is an sql and python question commonly asked in ikm

Uploaded by

Shaik Sajid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 33
1. f=open(‘filename.txt’}.readlines() A file handle A sorted array An error code The content of the file ‘ filename.txt’ A python list contacting all the lines in ‘filename.taxt’ pangs ANS: a, d,e 2. def test(x): if x%3==0: return test(x/3) if x%2==1: return x return test(2*x#1) test(100) Ans: 67 3. class vehicles: feunt—o 3. class vehicles: count=0 def__ init__(self, value): self.value = value vehicles.count += 1 def getval(selF): return self.value def getcount(cls}: return vehicles.count counter = classmethod(getcount) types1=vehicles(“car”) types2=vehicles(“Bus”) types3=vehicles(“Bike”) Ans. Car Bus 3 3 4. Which of the following statements correctly describe Bidirectional Forwarding Detection(BFD) ANS: a. BFDis enabled on the interfaces and at the router level to detect neighbor adjacency failures b. BFD must use object tracking to defect failures cr Twa made are availahla: acunchranniic and demand 4, Which of the following statements correctly describe Bidirectional Forwarding Detection(BFD) ANS: a. BFD Is enabled on the Interfaces and at the router level to detect neighbor adjacency failures b. BFD must use object tracking to defect failures c. Two modes are available: asynchronous and demand 5. Which of the following statements about POP3 are correct? ANSWERS: a. POP3 allows simultaneous access by multiple clients h PO? default< to leaving the meccace on the email server and iuct 10. Which of the following lines of python code correctly format the output: Ans: a. Print ("9% .2f" % 3.142) I> b. Print (“{: .2}". format (3.142)) ce. Print ("{n: .2f}". format(n=3.142)} 11, What is the output of the fallowing code? z=5 X= “456" While Z> -1; yox If ¥ in (‘1', 2", “3"): Break X=X+¥ If Yin ('4, 5’, 6): Continue Z=Z-1 Print(Z) 11. What is the output of the following code? z=5 X = “456” While Z > -1: Y¥=X If ¥in ('1', '2', ‘3°: Break Ke=eX+¥ lf ¥in ('4, 5’, 6”): Continue Z=Z-1 Print(Z) ANS: = -1 12. request = input("what's your favourite language?”) If request == “python”: response = “True!” else: response = "False" print(response) [> ns: a.response = ("True!” if request == “python” else “False”) b. response = “True!” if request == “python” else “False” 13. which of the following statements about UDP packets are correct? INS: a. TCP packets have a higher rate of corruption in transit than UDP packets d. UDP packets have a larger packet header than TCP packets e. UDP packets have a maximum size of 512 bytes on an Ethernet network 20. Whats the output of the following code 1= While True: If 63==0: Break Print(I) i+=1 ANS; 1 21. i=0 while i<3: print(i) i+=1 else: print(0) ANS: ony oO 22. i=0 while i _ 46, Which of the following python code snippet can be While text = f.readline() While text: do_something(text} text = f.readline() ANS: While text : = f.readline(): peo something ttext-readiinet)) 37. A python program is running and must open a file name “x.out” in a subdirectory next 2 of a subdirectory next 1 of the current directory(thus, two directories down), which of the following are portable ways to accomplish this? ANS: I Import os fh = open(os.path.join(“next1”, “next2”, “x”, “out”)) 23. for iin range(i0)}: if i==5: break else: print(i) else: print(“Here") RwhPH oO 61, A programmer writes the python class below, able to handle managed attributes. Which of the following statements correctly define the concepts implemented in the class? class subject (): count =0 def__ init__(self, name): self.name = name def set (self, name): self__name = name def getlself): return self._name name = property(get, set) ANS: a. get () and set () are python special methods b. Attribute access can also be accomplished by overriding __petattr__and__setattr__ 51. Which of the following expressions can be used to open a binary file so that it contents can be read reliably on your systems? ls ANS: of = open(filename, “rb”) 62. Which of the following python statement will return a tuple of two values from aand b ANS: a. return (x,y) b. return xy 74. While optimizing a python program, it is required to extract substring before and after a given separator and then return a three-tuple slices. Which of the following string methods will help accomplish ANS: strip {) ls 75. Which of the following python code snippets will print the value of ‘1°? ANS: a=1 def test(): global a if True: return a else: a=2 print(test()) 108. class c: count: =0 def __init__(self): self. = c.count c.count = c.count +1 def getcount(self): return self.l ANS: self 109. while temperature<98.6: for iin samples: ifi == temperature: temperature = temperature 47 temperature = temperature 41 ANS: 103 110. self.Num = self.num +1 def method{self): self.num =I.num return self.num ANS: |.methodB() 112. return x+y+z ellf x==7: return x*y*z else: return 42 ANS: 32 111. which of the following python functions will allow ato b to get the size of a file in bytes? ANS: a. importos f = open (file, “r") size = f.seek (OS.SEEK_SET) bb b. import os import start size = os.stat {filename)[stat.ST_SIZE) 112, return x+y4z elif x==7: return x*y*z else: return 42 113. which of the following correctly identify for nin range (2,10): for x in range (2,n): if n%x==0: break else: print(n) Ls ANS: 4 114. once the bug is fixed and the status is changed to “IN TEST”, the tester tests the bug If the bug is not reproducible in the software tester changes the status to ANS: verified 121, In the python class below , which of the following python names can be replayed by the word “this “ without breaking or altering the current logic? class C: count=0 def_ init__(self}: self.l=C.count C.count=C.count+1 def getcount(self): return self. (ANS----A} options: A. Self _init__ Def Is Class Return moos 120. Which of the following willbe returned as the result of executing feopen({"filename”,”a”) in python? (ANS---D) Options: A. The content of the filename “filename” as a single string. B. Ahandle open to an empty file named “filename” which can be , if filename Is not empty. C. The contents of the file “filename” as a list of lines. DB. Ahandle open to a file(possibly already existing) named “filename” which can be written to. E, Ahandle open to the existing file named “filename” which can be read from. 122. Which of the following python code snippets can be used as a shorter version of the code below with the Walrus operator? Text=f.readline{) While text: Do _something{Text) Text=f.readline() ‘OPTIONS: A. while text:f.readline(): do. somethingitextJeadline()) B. while text: text: fLreadline(): do_something(text.readline()) C. while text: =f.readline(): do_something(text) D. while text:= f.readline(): do_something() E. while text: do_something(text.=f()) 123. Which of the following python functions will allow a developer to get the size of a OPTIONS: A: size =sys.filesize(filename} B: import os. f=open(filename,"r”) size=f.seek(os.SEEK_SET) C: import fileinfo Size=fileinfo.size(filename) D: import os ‘Size =os.stat.size(filename) E: import os Import stat Size =os.stat(filename){stat.ST_SIZE] C: fh=open(“nexti/next2/x.out") D: fh=open("next1\next2\x.out”) E: import os Fh=open(os.path.unixtolocal{"nexti/next2/x.out”)) 125, Which of the following code snippets will construct a function that returns the filename unchanged, and stores that function in the dictionary with operation name id? A: def foo(filename): return filename functions[foo]=="id" B: def foo(filename): return filename functions(“id”]()=foo C: functions["|d"]= lambda filename: filename D: def foo(filename): return lambda filename:filename Functions[“id"]=foo E: def foo(filename): return filename 124. Apython program is running and must open a file name “x.oul” in subdirectory next2 of a subdirectory next1 of the current directory(thus,two directories down). Which of the following are portable ways to accomplish this? OPTIONS: A: import os. Fh=open(os.path.join(“next1”,"next2”, “x”, “out”)) B: import os path=os.path join(“nexti”,"next2”, “x”, “out”) fh=open(path) 127. which of the following python code snippets will prompt a user for input and read a single line of input a) line = input("enter user input\n") b) import sys print((sys.stdoubt,"enter user input\n")) read(line) c) printf("enter the user input\n") line = fgets0 Al imnanrt cuc 130. sort ip list in ascending numerical order? a, IPlist.sort(Key=lambda address: list(rmap(str, address.split(’.')))) 128. which of the following correctly describe what will be in f after executing the python code f=open('filename.txt’).readlines()[ ANS: AE] A: A filehandle B: an error code C: A sorted array D: The content of the file 'filename.txt" E: A python list containing all the lines in ‘filename.bet’, 129. class k: I def _init_(self): self._ foo = 10 def methodX (self): self,_methodY () print (self,_foo) def _ methodY (self): self. foo +=1 o=k({) a) o.methodX() b) o._fooQ c) ok_methodY¥ 0) d) o_ init) e)o._methodY0) 131. which of the following flow control statements are valid python instructions? ANS: a. while c. for which of the following statements are correct regarding the code I 132. def myGenerator(stop): z=0 while z < stop: yieldz*2 z+=1 g=myGenerator(4) for ning: print(n, end=' 4) ANS: a. gis generator object b. zisa yield object c. the program outputs: 0246 133. while True: tmp = [num{i]] + tmp j+=1 ifi > len(num4}: break numi = tmp ANS: num = [17, 13, 11, 7,5, 3, 2] Numi = numif[: ; -1] 134, Apython script must generate a password of length n from a string. Neither the string that generates the password nor the generated password should have any duplicate characters. Which of follawing code snippets will accomplish this? Assume the variable values below: String = “avsdbc" n=3 ANS: a. import random I password =‘ ‘ join(random.choice(string) for _ in range(n)) b. string = random.choice(string) Ist = [string for x in range(n)] password = * ‘ join(lst)

You might also like