You are on page 1of 9

LOCAL TEST FOR BATCH 2 .

1.Which of the following is most like an open socket in an application?

a)Fiber optic cables


b)An "in-progress" phone conversation
c)The ringer on a telephone
d)The chain on a bicycle
d)The wheels on an automobile

2.Which of the following TCP sockets is most commonly used for the web protocol
(HTTP)?

a)80
b)23
c)22
d)119
e)25

3.What must you do in Python before opening a socket?

a)import tcp-socket
b)open socket
c)import tcp
d)import socket
e)_socket = true

4.In a client-server application on the web using sockets, which must come up
first?

a)it does not matter


b)server
c)client

5.Code(1 OR MORE THAN 1)

<person>
<name>Chuck</name>
<phone type="intl">
+1 734 303 4456
</phone>
<email hide="yes" />
</person>

a)person
b)name
c)email
d)type
e)hide

6.What is the method to cause Python to parse XML that is stored in a string?

a)xpath()
b)parse()
c)extract()
d)fromstring()
e)readall()

7.Structured Query Language (SQL) is used to (check all that apply)


a)Check Python code for errors
b)Delete data
c)Insert data
d)Create a table

8.What happens if a DELETE command is run on a table without a WHERE clause?

a)It is a syntax error


b)The first row of the table will be deleted
c)All the rows in the table are deleted
d)All the rows without a primary key will be deletedWhat happens if a DELETE
command is run on a table without a WHERE clause?

9.Can we pass List as an argument in Python function?

a)Yes
b)No

10.Which of the following are valid string manipulation functions in Python?(ONE OR


MORE)

a)count
b)upper
c)strip()
d)All of the above

11.
What will be the output of the following code snippet?

a = "4, 5"
nums = a.split(',')
x, y = nums
int_prod = int(x) * int(y)
print(int_prod)

a)20
b)45
c)54
d)4,5

12.
What will be the output of the following code snippet?

word = "Python Programming"


n = len(word)
word1 = word.upper()
word2 = word.lower()
converted_word = ""
for i in range(n):
if i % 2 == 0:
converted_word += word2[i]
else:
converted_word += word1[i]
print(converted_word)

a)pYtHoN PrOgRaMmInG
b)Python Programming
c)python PROGRAMMING
d)PYTHON PROGRAMMING

13.What will be the output of the following code snippet?

def is_even(number):
message = f"{number} is an even number" if number % 2 == 0 else f"{number} is
an odd number"
return message
print(is_even(54))

a)54 is an even number


b)54 is an odd number
c)number is an even number
d)number is an odd number

14.What will be the output of the following code snippet?

a = [1, 2]
print(a * 3)

a)Error
b)[1,2]
c)[3,6]
d)[1,2,1,2,1,2]

15.What's the output!

What will be the output of the following code snippet?

a = [1, 2 , 3 , 4 , 5]
sum = 0
for ele in a:
sum+= ele
print(sum)

a)15
b)0
c)20
d)None of these

16.What will be the output of the following code snippet?

a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)

a)[2,2,3]
b)(2,2,3)
c)(1,2,3)
d)Error

17.
What will be the output of the following code snippet?

print(2**3 + (5 + 6)**(1 + 1))

a)129
b)8
c)121
d)None of the above

18.. What will be the output of the following Python expression?

round(4.576)
a) 4
b) 4.6
c) 5
d) 4.5

19. What will be the output of the following Python program?

def addItem(listParam):
listParam += [1]

mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))
a) 5
b) 8
c) 2
d) 1

20.What will be the output of the following Python code?

x = 'abcd'
for i in range(len(x)):
print(i)

a) error
b) 1 2 3 4
c) a b c d
d) 0 1 2 3

21.What will be the output of the following Python program?

i = 0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) error
b) 0 1 2 0
c) 0 1 2
d) none of the mentioned

22.Which of the following Python statements will result in the output: 6?

A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]

a) A[2][1]
b) A[1][2]
c) A[3][2]
d) A[2][3]

23.)What will be the output of the following Python program?

def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

a) Error
b) None
c) False
d) True

24.)What does the following command do?

Returns True if file path is an existing directory

a)getcwd()
b)isdir()
c)isfile()
d)abspath()

25.What is the correct command.

a)isexists()
b)exists()
c)exist()
d)ifexist()

26.Which of these files (refresh in the browser to get the new data.)

a)spider.json
b)spjson.py
c)spreset.py
d)spdump.py

27.Which of these files(is used as a data analysis)

a)gmane.py
b)gmodel.py
c)gbasic.py
d)gword.py

28.what does get() method when used with a dictionary.

a)Returns value of give key or returns default if key not in dictionary.


b)Returns true if key in dictionary "dict" flase otherwise
c)Returns a lists of keys from dictionary
d)set dict[key] = defualt if key is not in "dict"

29.What does findall() do? (re.findall())


(ONE OR MORE)

a)Extracts data from a string.


b)Returns all non-overlapping matches patter in string
c)Returns a list of groups if one or more groups found.
30.Which of these is a assignment operator?.
(ONE OR MORE)
a)=
b)>=
c)==
d)-

31.Which of these data types is written the most versatile datatype in python.
(ONE OR MORE)

a)List
b)String
c)Int
d)Tuple

32.Code
L = ['a','b','c','d']
print("".join(L))L = ['a','b','c','d']

a)Error
b)None
c)abcd
d)['a','b','c','d']

33.Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?
A
[3, 4, 5, 20, 5, 25, 1, 3]
B
[1, 3, 3, 4, 5, 5, 20, 25]
C
[3, 5, 20, 5, 25, 1, 3]
D
[1, 3, 4, 5, 20, 5, 25]

34.Suppose t = (1, 2, 4, 3), which of the following is incorrect?


a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))

35.What will be the output of the following Python code?

>>>t=(1,2,4,3)
>>>t[1:-1]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)

36.What will be the output of the following Python code?

d = {"john":40, "peter":45}
d["john"]
a) 40
b) 45
c) “john”
d) “peter”
37. What will be the output of the following Python code?

numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
a) 30
b) 24
c) 33
d) 12

38.Which of the following is correct with respect to above Python code?


d={"a":3,"b":7}
(ONE OR MORE)
a) a dictionary d is created.
b) a and b are the keys of dictionary d.
c) 3 and 7 are the values of dictionary d
d) All of the above.

39.What is the output of the following code


dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
A. True
B. False

40.What provides two way communication between two different programs in a network.

A. socket
B. port
C. http
D. protocol

41.What does the following block of code do?

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\r\n\r\n'.encode()
mysock.send(cmd)

a) It sends a request to extract 'romeo.txt' from 'data.pr4e.org'


b) It sends the 'romeo.txt' file to 'data.pr4e.org'
c) It creates a file named 'romeo.txt'
d) It throws an error because a socket cannot use HTTP.

42.What does the following block of code do?

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


mysock.connect(('data.pr4e.org', 80))
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\r\n\r\n'.encode()
mysock.send(cmd)
A. It sends a request to extract 'romeo.txt' from 'data.pr4e.org'
B. It sends the 'romeo.txt' file to 'data.pr4e.org'
C. It creates a file named 'romeo.txt'
D. It throws an error because a socket cannot use HTTP.
43.Identify the type of exception will be thrown by given code:

L=[12,32,40]
print(L[3])
a)IndexError
b)Zero division Error
c)TypeError
d)No Error

44.Select the correct mode to open a file for appending as well as reading

a)a+
b)ar
c)rw
d)ar+

45.Which method is used to sets the position of a file pointer

a)ftell()
b)fseek()
c)tell()
d)seek()

46.Code

import sqlite3

conn = sqlite3.connect('College.sqlite3')
cur = conn.cursor() line1
cur.execute('DROP TABLE IF EXISTS Student')line2
cur.execute('CREATE TABLE Student(StudentID INTEGER, StudentNName TEXT)')line3
courr.close() line4

a)line1 error should be con.cursor()


b)line 2 error Exists should be spelled exist
c)line4 error
d)line3 error because there's no .commit()

47.str1 = "my isname isisis jameis isis bond";


sub = "is";
print(str1.count(sub, 4))

a)5
b)6
c)7

48. Select the correct output of the following String operations

str1 = 'Welcome'
print (str1[:6] + ' PYnative')

a)Welcome PYnative
b)WelcomPYnative
c)Welcom PYnative
d)WelcomePYnative

49.. Select the correct output of the following string operations


myString = "pynative"
stringList = ["abc", "pynative", "xyz"]

print(stringList[1] == myString)
print(stringList[1] is myString)

a)
True
False

b)
True
True

c)
False
True

d)
False
False

50.what does getcwd()commands do

a)Returns absolute version of the file pathname


b)Returns True if file path is an existing directory
c)Returns True if file path is an existing regular file
d)Returns current working directory of a process

You might also like