Knowledge check.
- Choose one best answer from given 4 choices for each questions.
- Review before submit as you wont get a chance to review after submit.
- Max Time for quiz is 30 mins and Exam is 90 mins.
- Login is not required for an exam or a quiz.
- By submitting you formally acknowledge and accept terms and conditions mentioned here.
Python has a built in data type to support complex numbers. State true or false.
Give the output of the following code snippet:
class MyClass:
def PrintList1(*args):
for count,Item in enumerate(args):
print("{0}. {1}".format(count,Item))
MyClass.PrintList1("Red", "Blue")
Which of the following statements are true about the host part of the email address?
Give the output of the following code snippet:
List = ["Hello"]*2 + ["World"]
Result = 0
List.insert("Hello")
for value in List:
Result += 1
List.clear()
print(Result)
Which of the following string functions is used to convert all the characters in a string to lowercase?
Which of the following commands can be used to execute an application from python shell window?
Give the output of the following code snippet:
List = [1,2,4,5.5]
Result = 0
List.append("Hello")
for value in List:
Result += value
print(Result)
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = 6):
Arg **=2
Arg /=2
print(Arg)
>>> Test(int("Hello"))
Which of the following statements is true about the os._exit() command in python?
Which colour in the Python IDLE specifies the content sent to a command?
Give the output of the following code snippet:
class MyClass:
age = 0
def __init__(self,age = 10):
self.age = age + 20
def PrintAge(self):
print(self.age)
def Greet(self):
print("Hello")
MyInst = MyClass(10)
MyInst.Greet()
Give the output of the following code snippet :
#print("Red " +
"Yellow" +
"Blue")
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","r+")
file3 = open("Test2.txt","w+")
string = file.read(5)
file3.write(string)
file3.seek(0,0)
string1 = file3.read(5)
file.close()
file3.close()
print (string1)
What are the key components of the server side for which the tutorials are provided for?
Give the output of the following code snippet:
Formatted = "{;*>8X}"
print(Formatted.format(1000))
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Hello World Program' and 'Test2.txt' does not exist.
file = open("Test.txt","r")
file2 = open("Test2.txt","r+")
file.seek(8,0)
string = file.read()
file2.write(string)
string = file2.tell()
file.close()
file2.close()
print (string)
Which method displays the current working directory?
Give the output of the following code snippet:
List = ["Hello","World"]*2 + ["!"]*2
Result = 0
for value in List:
Result += 1
if(value == '!'):
Result -= 2
else :
List.pop(3)
Result += 2
print(List)
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","a")
file.write("Program")
file.seek(0,0)
string = file.read()
file.close()
print (string)
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = str(123)+ str(45)):
print(str(123))
>>> Test(23)
Give the output of the following code snippet:
List = [1,2] + [11,10]
Result = 0
List2 = List.copy()
List2.reverse()
List3 = List + List2
List3.sort()
print(List3)
|
|
|
|
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' and 'Test2.txt' contains the string ' Green Yellow'.
file = open("Test.txt","a")
file2 = open("Test2.txt","w")
file.seek(5,0)
string = file.read()
file2.write(string)
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet:
var = 1
for Arg in str(var):
var += 1
print(var)
Give the output of the command given in the shell window if the file Test.py contains the following line of code :
print("Hello World")
>>> exec( ("c:\\Test.py").read())
Give the output of the following code snippet : Assume the file is not present
import sys
try :
File = open('Test.txt')
except IOError as e:
print("Error opening file " + "Error number : {0} ".format(e.err) +
"Error text :{0}".format(e.strerror))
else:
print("File opened")
File.close()
Which python product can be used to make unit testing easier?
The date and time obtained can be converted to a more readable format using which command?
Give the output of the following code snippet:
var = 1
for Arg = 0
var += 1
print(var)
Give the output of the following code snippet:
## LibTest.py
def SayHello(Name):
print("Hello",Name)
return
def SayAge(Age):
print("Age : ", Age + 10)
return
>>> import from LibTest SayHello
>>> SayAge(10)
Give the output of the following code snippet:
## LibTest.py
def SayHello():
print("Hello")
PrintAge(10)
return
def PrintAge(Age):
print(Age + 10)
return
>>> from LibTest import SayHello
>>> SayHello()
What are the two subparts of the content of the email?
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' and 'Test2.txt' contains the string ' Green Yellow'.
file = open("Test.txt","r")
file2 = open("Test2.txt","w")
file.seek(0,0)
string = file.read()
file2.write(string)
string1 = file2.read()
file.close()
file2.close()
print (string1)
Give the output of the following code snippet:
List = [1,2,4,5.5]
Result = 0
for value in List:
Result += value
if(Result > 0):
Result += 1
print(Result)
Give the output of the following code snippet in the python shell window:
>>> var = ~0b1001
>>> var
Which of the following statements are true regarding the use of platform independent libraries?
Give the output of the following code snippet :
""
print("Red " +
"Yellow" +
"Blue")
""
Give the output of the following code snippet :
import sys
try :
## raise ValueError
print("Begin Test")
except (ValueError):
sys.exit()
finally:
print("Hello")
print("End")
Which of the following are built in Python exception categories that the user regularly works with?
How is the direct help method useful in python?
Give the output of the following code snippet :
>>> myvar = 2.55e-3 / 1.25e-1
>>> myvar
Name a technique for creating specialized versions of simple functions that derive from more complex functions :
Which is the library that helps you create Simple Object Access Protocol (SOAP) connections to Web services providers?
Give the output of the following code snippet:
var = 1
for Arg in range(1,1):
if(Arg == 1):
break
var += 5
else :
var -=5
print(var)
Give the output of the following code snippet :
value = 10
if(value >= 10//8 ):
print(value **2)
else:
print(value + 10)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' and 'Test2.txt' contains the string ' Green Yellow'.
file = open("Test.txt","a+")
file2 = open("Test2.txt","w")
file.seek(5,0)
string = file.read()
file2.write(string)
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet : Assume the inputs given for value1 = 10 and value2 = 20.5
try :
value1 = int(input("Enter first value:"))
value2 = int(input("Enter second value:"))
Result = value1/value2
except (ValueError):
print("Enter whole number")
except (KeyboardInterrupt):
print("Interrupt detected")
except (ZeroDivisionError):
print("Cannot divide by zero")
except (ArithmeticError):
print("Undefined Math error")
else :
print(Result)
Which of the following libraries makes it easy to add an appealing tabular presentation to your command-line application?
Which of the following are true with regards to indentation in an IDLE?
Give the output of the following code snippet:
var = 0
string = "Hello World"
for Arg in string:
if(Arg == '' or 'l'):
var +=2
else :
var += 5
print(var)
Which library ensures special audio support for gamers to hear special effects?
Give the output of the following code snippet in the python shell window:
>>> var = int("100",2)
>>> if ( 1 <= 1):
var //= 3
var <<= 2
print (var)
Give the output of the following code snippet:
List = ["Hello","World"]*2 + ["!"]*2
Result = 0
List.clear()
for value in List:
Result += 2
if(value == '*'):
Result -= 2
else :
Result += 2
print(Result)
Give the output of the following code snippet:
var = 0
string = "Hello"
for Arg in string:
var += 1
print(var)
Which attribute is used to provide the name of the module?
Give the output of the following code snippet :
>>> myvar = 0o100
>>> myvar += 100
>>>myvar
Give the output of the following code snippet:
string = "This is a test program that is to test string functions"
Result = string.find ("prog")
print(Result)
Give the output of the following code snippet:
#!/usr/bin/python
MyTuple = ("Red","Blue")
MyTuple = MyTuple.__add__((20,10))
print(MyTuple)
Which are the two major time frames in Python during which the error occurs?
What are the key components of the server side for which the tutorials are provided for?
Which of the following logical operators in python is used to negate the value of the operand?
Give the output of the following code snippet:
string = "Hello World"
Result = string.rjust(15,"*")
print(Result)
Give the output of the following code snippet :
>>> myvar = 0b100
>>>hex(myvar)
Give the output of the following code snippet:
var = 0
string = "Hello"
for Arg in string:
if(Arg == 'e'):
var += 1
else :
var -=1
print(var)
Give the output of the following code snippet:
string = "1234 WORLD"
Result = string.islower()
print(Result)
Which of the following statements are true about the class variables?
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","a+")
file.read(5)
string = file.tell()
file.write("Program")
file.close()
print (string)
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = str(123)):
print(Arg + str(45))
>>> Test()
Which of the following statements are true about the finally clause?
Which environment variable is used to specify the encoding for stdin, stdout and stderr devices?
Give the output of the following code snippet:
var = 1
for Arg in "Hello";
var += 1
print(Arg)
The finding of geographic coordinates, such as longitude and latitude from geographic data, such as address, is known as :
What are the features of the python debugger?
Give the output of the following code snippet:
List = ["Hello"] + ["World"] * 2
Result = 0
List.append("Hello")
for value in List:
Result += 1
print(len(List))
Give the output of the following code snippet:
class MyTest:
var = 0
def SayHello():
print("Hello")
SayHello()
Which of the following command line option in python if used to perform additional optimization by removing doc-strings?
Give the output of the following code snippet:
#!/usr/bin/python
DList = {"B": 10, "B": 20,"C1" : 30}
DList2 = {"A": 5,"B" : 40}
print(DList2["B"])
Give the output of the following code snippet:
string = " Hello World "
Result = string.lstrip()
print(Result)
Give the output of the following code snippet:
class MyClass:
def PrintList2(**kwargs):
for count,Item in kwargs.items():
if(count == 'A'):
print("{0}".format(Item[0]))
MyClass.PrintList2(A="Red",B="Blue")
How many arguments does the method socket.getaddrinfo() take?
Give the output of the following code snippet:
string = "Hello#World Program"
Result = string.split("#")[1]
print(Result)
Give the output of the following code snippet:
class MyClass:
def PrintList1(self,*args):
for count,Item in enumerate(args):
if(count == 0):
print((Item))
def PrintList2(self,**kwargs):
for count,Item in kwargs.items():
if(count == 0):
print(Item[1]+Item[1])
List2 = MyClass()
List2.PrintList2(C = 100,A="Green",B="Yellow")
List2.PrintList1(1,"Red")
Give the output of the following code snippet:
var = 1
for Arg in range(1,3):
if(Arg == 2):
break
var += 5
print(var)
The elementtidy and celementtree are add-ons to which of the following libraries?
Give the output of the following code snippet : Assume the input given in 40.
try :
value = int(input("Enter value from 1 to 50:"))
except:
print("Invalid")
else :
if(value > 0 ) and (value <= 50):
print(value)
else :
print(0)
Give the output of the following code snippet:
var = 1
while (var != 10):
var += 1
else :
var += 2
print(var)
What does the color Yellow in the Python IDLE indicate?
Which of the following statements are true about dictionaries in Python?
Which library makes it possible to access most (but not all) of the Java libraries out there directly from Python?
Which of the following statements are true about IPython?
Give the output of the following code snippet : Assume the input given in 5.
try :
value = int(input("Enter number from 1 to 10:"))
exception ValueError :
print("Invalid number")
else:
if(value > 0 ) and (value <= 10):
print(value)
else :
print("Invalid value")
Which option in the File menu is used to close the current window and its associated windows?
Give the output of the following code snippet:
class MyClass:
age = 0
def __init__(self,age = 10):
self.age = age + 20
def Greet(self):
print("Hello")
def PrintAge(self):
print(self.age)
MyClass.age = 10
MyInit = MyClass(20)
MyInit.PrintAge()
Give the output of the following code snippet:
class MyClass:
def __init__(self, *args):
self.Input = args
def __add__(self, Other):
Output = MyClass()
Output.Input = self.Input + Other.Input
return Output
def __str__(self):
Output = ""
for Item in self.Input:
Output += Item
Output += " "
return Output
Value1 = MyClass("Red", "Green")
Value2 = MyClass("Blue", "Purple")
Value3 = Value1 + Value2
print("{0} + {1} = {2}".format(Value1, Value2, Value3))
Which command is used to convert a numeric value to hexadecimal in Python?
Give the output of the following code snippet in the python shell window:
>>> var = "Hello" NOT IN "Hell World"
>>> var
Which of the following commands is used to obtain the host address for a hostname?
Which testing stage is associated with checking the application for errors?
Give the output of the following code snippet : Assume the file is not present
import sys
try :
File = open('Test.txt')
except IOError as e:
print("Error opening file " + "Error number : {0} ".format(e.errno) +
"Error text :{0}".format(e.strerr))
else:
print("File opened")
File.close()
Which method is used to provide the current position of the pointer in the file?
Which method is used to change the current file position?
Which of the following statements are true about the class variables?
Which option forces python to let the user inspect the code interactively after running a script?
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test2.txt","r")
file2 = open("Test3.txt","w+")
string = file.read()
file2.write(string)
file2.seek(5,0)
string1 = file2.read()
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet in the python shell window:
>>>def TestFun(Arg = 10):
return(Arg+1)
return(Arg+2)
>>>TestFun()
Give the output of the following code snippet :
import socket
print(socket.getservbyport())
Which of the following is used to indicate a multiline comment?
Which MIME form is used to provide a method for sending and receiving application input and output?
Give the output of the following code snippet:
class MyClass:
def __init__(self,Age,Name="John"):
self.Name = Name
self.Age = Age
def GetName(self):
return self.Name
def SetName(self, Name):
self.Name = Name
def GetAge(self):
return self.Age
def SetAge(self, Age):
self.Age = Age + 10
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
JohnRecord = MyClass(50)
JohnRecord.SetAge(10)
AnnaRecord = MyClass("Amy", 44)
print(JohnRecord.GetAge())
Give the output of the following code snippet:
print("Hello")
print('World')
print("""Multiple line text.
This is an example""")
The finally clause is always executed even if the exception is not raised. State true or false
To obtain a list of attributes associated with the error argument object, which function can be used?
For the open() function to access a file, what is the action taken if the buffering value is set to 1?
Give the output of the following code snippet:
class MyClass:
def __init__(self, *args):
self.Input = args
def __add__(self, Other):
Output = MyClass(self)
Output.Input = self.Input + Other.Input
return Output
def __str__(self):
Output = ""
for Item in self.Input:
Output = Item
return Output
Value1 = MyClass("Red", "Green")
Value2 = MyClass("Blue", "Purple")
Value3 = MyClass("Black", "White")
Value = Value2 + Value1 + Value3
print("{0} + {1} = {2}".format(Value1, Value2, Value3))
Which of the following statements are true regarding the library JPype?
Which of the following are true with regards to modules in Python?
Give the output of the following code snippet:
class MyClass:
def __init__(self,Age,Name="John"):
self.Name = Name
self.Age = Age
def GetName(self):
return self.Name
def SetName(self, Name):
self.Name = Name
def GetAge(self):
return self.Age
def SetAge(self, Age):
self.Age = Age + 10
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
JohnRecord = MyClass(50)
AnnaRecord = MyClass("Amy", 44)
print(JohnRecord.GetAge())
Give the output of the following code snippet:
var = 1
for Arg in "Hello"
var += 1
print(var)
What does the color Black in the Python IDLE indicate?
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","r")
file.write("Program")
file.seek(0,0)
string = file.read(5)
file.close()
print (string)
Give the output of the following code snippet:
class MyClass:
def PrintList2(**kwargs):
for count,Item in kwargs.items():
if(count == 'A'):
print("{0}".format(Item[0]))
else :
print("{0}".format(Item[0]+Item[0]))
MyClass.PrintList2(A="Red")
MyClass.PrintList2(A="Green",D="Yellow")
Give the output of the following code snippet:
class MyClass:
def __init__(self,Age,Name="John"):
self.Name = Name
self.Age = Age
def GetName(self):
return self.Name
def SetName(self, Name):
self.Name = Name
def GetAge(self):
return self.Age
def SetAge(self):
self.Age = 10
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
JohnRecord = MyClass(50)
JohnRecord.SetAge()
AnnaRecord = MyClass("Amy", 44)
print(JohnRecord.GetAge())
Give the output of the following code snippet:
class MyClass:
def __init__(self,Age):
self.Age = Age
def GetAge(self):
return self.Age
def SetAge(self,Age):
if(Age > 30):
self.Age = Age + self.Age
else:
self.Age = 20
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
JohnRecord = MyClass(50)
JohnRecord.SetAge(20)
AnnaRecord = MyClass(44)
print(JohnRecord.GetAge())
Give the output of the following code snippet in the python shell window:
>>> var = not(100 and 20)
>>> var
Give the output of the following code snippet:
string = "Hello World"
print((string[: 3]* string[:2])+2)
Which of the following is true about the library grabscreen?
Give the output of the following code snippet:
class MyClass:
def PrintList1(self,*args):
for count,Item in enumerate(args):
if(count >= 0):
count = count -1
print(count)
def PrintList2(self,**kwargs):
for count,Item in kwargs.items():
if(count != 0):
continue
print(Item[0])
break
List2 = MyClass()
List2.PrintList2(A="Green",B="Yellow",C="Red")
List2.PrintList1(1,2,3,"Blue")
Give the output of the following code snippet : Assume the input given in 10.
try :
value = int(input("Enter number from 1 to 10:"))
except ValueError :
print("Invalid number")
else:
if(value > 0 ) and (value <= 10):
print(value)
else :
print("Invalid value")
Give the output of the following code snippet:
class MyClass:
def PrintList2(*args):
for count,Item in enumerate(args):
while(count != 0):
print("{0}".format(Item[0]))
break
else :
print("{0}".format(Item[0]+Item[0]))
MyClass.PrintList2("Red")
MyClass.PrintList2("Green", "Yellow")
What are the key components of the server side for which the tutorials are provided for?
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","r")
file2 = open("Test3.txt","w")
string = file.read()
file2.write(string)
file2.seek(0,0)
string1 = file2.read()
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet :
value = 100
if(value == 100/20):
print(value)
else
print(value + 100)
Give the output of the following code snippet:
List = [1,2,'Three',4.5]
print((List[0:1] +(List[:3]))[1])
Give the output of the following code snippet:
print("Hello")
print('World')
print(""Multiple line text.
This is an example"")
Give the output of the following code snippet:
class MyClass:
age = 0
def __init__(self,age = 10):
self.age = age + 20
def PrintAge(self):
print(self.age)
MyInst = MyClass(10)
MyInst.PrintAge()
Give the output of the following code snippet:
class MyClass:
def PrintList1():
for count,Item in kwargs.items():
print("{0}. {1}".format(count,Item))
MyClass.PrintList1(A="Red",B="Blue")
Give the output of the following code snippet:
class MyClass:
def __init__(self,Name = "",Age=0):
self.Name = Name
self.Age = Age
def GetAge(self):
return self.Age
def SetAge(self,Age):
self.Age = Age
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
class Anna:
def __init__(self, Age=0):
self.Name = "Anna"
self.Age = Age
self.Id = 1001
def SetName(self,Name):
print("Name cannot be changed")
def GetID(self):
return self.Id
JohnRecord = Anna()
JohnRecord.SetAge(30)
Which of the following statements is true about the add-on celementtree?
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","r+")
file2 = open("Test2.txt","r+")
file3 = open("Test3.txt","w+")
string = file.read()
file3.seek(0,2)
file3.write(string)
string = file2.read()
file3.seek(0,2)
file3.write(string)
file3.seek(0,0)
val = file2.tell()
file.close()
file2.close()
file3.close()
print (val)
Give the output of the following code snippet : Assume the file is not present.
import sys
try :
File = open('Test.txt')
except IOError as e:
for Arg in e.args:
print(Arg)
else:
print("File opened")
File.close()
Which is a utility for creating documentation from the comments in the Python code that works much like JavaDoc?
What are the kinds of documentations that are associated with applications?
Give the output of the following code snippet:
## LibTest.py
def SayHello():
print("Hello")
PrintAge(10)
return
def PrintAge(Age):
print(Age + 10)
return
>>> import LibTest
>>>SayHello()
Give the output of the following code snippet:
class MyClass:
def PrintList1(*args):
for count,Item in enumerate(args):
if(count == 0):
print((Item[0]))
def PrintList2(self,**kwargs):
for count,Item in kwargs.items():
if(count == 0):
print(Item[1]+Item[1])
MyClass.PrintList1("Red")
List2 = MyClass()
List2.PrintList2(A="Green",B="Yellow")
Which of the following statements are true about methods in Python?
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt")
print (file.read(10))
Give the importance of the -m mod command line option in python :
Which of the following Python installers can be used to install a program from your system to the user's system?
Name a method to generate new lists based on existing lists :
Give the output of the following code snippet : Assume the inputs given for value1 = 10 and value2 = 0.
try :
value1 = int(input("Enter first value:"))
value2 = int(input("Enter second value:"))
Result = value1/value2
except (ValueError):
print("Enter whole number")
except (KeyboardInterrupt):
print("Interrupt detected")
except (ArithmeticError):
print("Undefined Math error")
except (ZeroDivisionError):
print("Cannot divide by zero")
else :
print(Result)
Give the output of the following code snippet in the python shell window:
>>> def TestFun(Arg):
print("Hello")
>>> TestFun()
Give the output of the following code snippet:
List = [1,2,4,5.5]
Result = 0
List.delete(5)
for value in List:
Result += value
print(Result)
Give the output of the following code snippet :
>>> myvar = 0b100
>>> oct(myvar)
Give the output of the following code snippet:
var = 1
for Arg in 0:
var += 1
print(var)
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = 6):
Arg **=2
Arg /=2
print(Arg)
>>> Test(10)
Give the output of the following code snippet :
>>> myvar = 1!=0
>>> myvar
Give the output of the following code snippet:
class MyClass:
Sum = 0
def Calc(self,Val1 = 10, Val2=20):
Sum = Val1 * Val2/10
print(Sum)
MyExp = MyClass(20)
MyExp.Calc(40)
Which of the following logical operators in python is used to determine if one of the operators is true?
Which of the following statements are true about the Twisted Matrix library?
Which letter is used to indicate that the base of the number is 8 in Python?
Give the output of the following code snippet:
class MyClass:
def PrintList1(self,*args):
for count,Item in enumerate(args):
if(count >= 0):
count = count -1
print(count)
def PrintList2(self,**kwargs):
for count,Item in kwargs.items():
if(count != 0):
print(Item[0]+1)
break
List2 = MyClass()
List2.PrintList2(A="Green",B="Yellow",C="Red")
List2.PrintList1(1,2,3,"Blue")
Give the output of the following code snippet:
var = 1
while (var <= 10):
if( var != 2):
var += 2
break
else:
var -= 1
print(var)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","r+")
file2 = open("Test2.txt","r+")
file3 = open("Test3.txt","w+")
string = file.read()
file3.seek(0,2)
file3.write(string)
string = file2.read()
file3.seek(0,2)
file3.write(string)
file3.seek(10,0)
string3 = file3.read(5)
file.close()
file2.close()
file3.close()
print (string3)
Give the output of the following code snippet:
string = "Hello\nWorld\nProgram\n"
Result = string.splitlines()
print(Result)
Give the importance of the -c cmd command line option :
Give the output of the following code snippet:
class MyClass:
def __init__(self, **kwargs):
self.Input = args[0]
def __add__(self, Other):
Output = MyClass()
Output.Input = self.Input + Other.Input
return Output
def __str__(self):
Output = ""
for Item in self.Input:
Output += Item
Output += " "
return Output
Value1 = MyClass("Red", "Green")
Value2 = MyClass("Blue", "Purple")
Value3 = Value1 + Value2
print("{0} + {1} = {2}".format(Value1, Value2, Value3))
Which of the following statements are true about constructors in Python?
Give the output of the following code snippet : Assume the inputs given for value1 = 'Hello' and value2 = 'World'.
try :
value1 = (input("Enter first value:"))
value2 = (input("Enter second value:"))
Result = value1 + value2
except (ValueError):
print("Enter whole number")
except (KeyboardInterrupt):
print("Interrupt detected")
except (ArithmeticError):
print("Undefined Math error")
else :
print(Result)
Give the output of the following code snippet :
>>> myvar = 1 > 2
>>> myvar
What are some advantages of command line version of Python over IDLE?
Give the output of the following code snippet : Assume the file is not present.
import sys
try :
File = open('Test.txt')
except IOError:
for Arg in e:
print(Arg)
else:
print("File opened")
File.close()
Give the output of the following code snippet:
List = [1,2,4,5.5,7,8.25]
Result = 0
List.clear()
List.append(1)
for value in List:
if(value % 2 == 0):
Result -= 1
else:
Result +=1
List.append(1)
break
print(len(List))
Which method can be used to get information about both host address and port information?
Give the output of the following code snippet :
>>> myvar = 256.408e-2 / 2
>>> myvar
Give the output of the following code snippet:
class MyClass:
def PrintList1(self,*args):
for count,Item in enumerate(args):
if(count >= 0):
count = count -1
print(count)
def PrintList2(self,**kwargs):
for count,Item in kwargs.items():
if(count != 0):
print(Item[0])
break
List2 = MyClass()
List2.PrintList2(A="Green",B="Yellow",C="Red")
List2.PrintList1(1,2,3,"Blue")
Give the output of the following code snippet in the python shell window:
>>> def Test(Count,*ArgList):
for Arg in ArgList:
print(Arg)
>>> Test(2,10,20)
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt")
print (file.read())
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","w")
file.write("Program")
file.seek(0,0)
string = file.tell()
file.close()
print (string)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test3.txt","w+")
file2 = open("Test2.txt","a+")
string = file.read()
file2.seek(0,0)
file2.write(string)
string1 = file2.read()
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet:
var = 1
string = "Hello World"
for Arg in string:
if(Arg !='r'):
if(Arg == 'o' not 'l' and 'd'):
var +=1
print(var)
Give the output of the following code snippet:
var = 0
string = "Hello"
for Arg in string:
if(Arg == 'l'):
var +=2
pass
break
print(string)
print(var)
Which of the following statements are true about dictionaries in Python?
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = 100):
Arg //= 10
print(Arg)
>>> Test(20)
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","r+")
file.write("Program")
file.seek(0,0)
string = file.read(5)
file.close()
print (string)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' and 'Test2.txt' contains the string ' Green Yellow'.
file = open("Test.txt","w")
file2 = open("Test2.txt","w")
file.seek(5,0)
string = file.read()
file2.write(string)
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet:
class MyClass:
def PrintList2(*args):
for count,Item in enumerate(args):
while(count == 'A'):
print("{0}".format(Item[0]))
break
else :
print("{0}".format(Item[0]+Item[0]))
continue
MyClass.PrintList2(A="Red")
MyClass.PrintList2(A="Green",D="Yellow")
Expand MIME :
Give the output of the following code snippet:
## LibTest.py
def SayHello():
print("Hello")
PrintAge(10)
return
def PrintAge(Age):
print(Age + 10)
return
>>> from LibTest import SayHello,SayAge
>>> SayHello()
Give the output of the following code snippet:
## LibTest.py
def SayHello():
print("Hello")
PrintAge(10)
return
def PrintAge(Age):
print(Age + 10)
return
>>> from LibTest import SayHello :
>>> SayHello()
Give the output of the following code snippet:
string = "Hello World"
Result = string.fill(12)
Result1 = Result.center(15,"*")
Result2 = Result.lower()
print(Result2)
Give the output of the following code snippet:
var = 1
for Arg in range(1,3):
if(Arg <= 3):
pass
var += 5
print(var)
To view the data type of a variable, which function is used in the python shell window?
Give the output of the following code snippet in the python shell window:
>>> def Fun(Arg = "No value"):
print(Arg)
>>> Fun()
Give the output of the following code snippet:
#!/usr/bin/python
MyTuple = ("Red")
MyTuple = MyTuple.__add__(("Green"))
MyTuple = MyTuple.__add__(("Yellow"))
print(MyTuple)
Which of the following commands are used to exit the python command prompt if the session is not ended properly?
Which command is used to convert a numeric value to binary in Python?
Give the output of the following code snippet :
value = 10
if(value == (10//5)):
print(value)
else if (value != 10//2)
print (value+1)
else :
print(value - 1)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","r+")
file2 = open("Test2.txt","a+")
file3 = open("Test3.txt","a+")
string = file.read()
file3.seek(0,2)
file3.write(string)
string = file2.read()
file3.seek(0,2)
file3.write(string)
val = file3.tell()
file.close()
file2.close()
file3.close()
print (val)
Give the output of the following code snippet : The contents of the file is a string 'Hello World'
file = open("Test.txt","a+")
file.write("Program")
file.seek(1,1)
string = file.read()
file.close()
print (string)
Which of the following is a library for working with FTP sites?
Give the output of the following code snippet:
class MyClass:
def __init__(self,Name = "",Age=0):
self.Name = Name
self.Age = Age
def GetAge(self):
return self.Age
def SetAge(self,Age):
self.Age = Age
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
class Anna(MyClass):
def __init__(self,Name = "X", Age=0):
self.Name = Name
self.Age = Age
self.Id = 1001
def GetID(self):
return self.Id
JohnRecord = MyClass()
AnnaRecord = Anna()
AnnaRecord.SetAge(30)
print(AnnaRecord)
Give the output of the following code snippet:
## LibTest.py
def SayHello():
print("Hello")
return
def SayAge(Age):
print("Age : ", Age + 10)
return
>>> from LibTest import SayHello
>>> LibTest.SayHello()
Give the output of the following code snippet :
>>> myvar = 0o16
>>> bin(myvar)
Give the output of the following code snippet:
string = "This is a test program that is to test string functions"
Result = string.replace("test","new")
print(Result)
The IOError exception provides access to which of the following arguments?
Which of the following statements is true about the add-on wckgraph?
Give the output of the following code snippet in the python shell window:
>>> var = 20
>>> var += ~0b100
>>> var
Give the output of the following code snippet in the python shell window:
>>> var = ~2 + (-4) - ~1
>>> var
Give the output of the following code snippet:
Formatted = "{=*>8X}"
print(Formatted.format(1000))
Which method provides the means to determine how a particular port is used?
Give the importance of the -S command line option in python :
Which of the following statements are true about lists in Python?
What are the components of an email address?
Which of the following arguments to methods is used to provide a named list of unnamed arguments?
Give the output of the following code snippet:
var = 0
for Arg in range(1,5):
var += 5
else:
break
print(var)
Which of the following statements are true about function overloading?
Which of the following statements are true for a single line comment in the edit window?
Give the output of the following code snippet:
List = ["Hello"]*2 + ["World"]
Result = 0
List.remove("Hello")
for value in List:
Result += 1
print(len(List[0]))
Give the output of the following code snippet in the python shell window:
>>> var = "Hell" not in "Hell World"
>>> var
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = str(23)):
print(Arg + str(45))
>>> Test(10)
Give the output of the following code snippet : Assume the input given in 0.0
try :
value = int(input("Enter value from 1 to 50:"))
exception:
print("Invalid")
else :
if(value > 0 ) and (value <= 50):
print(value)
else :
print(0)
Give the output of the following code snippet in the python shell window:
>>> var = 10
>>> if ( 0 != 1):
var //= 3
var **= 2
print (var)
Give the output of the following code snippet:
string = "12345"
Result = string.isdigit()
print(Result)
Give the output of the following code snippet :
value = 5
if(value == (10/2)):
if(value > 0):
value -= 1
print(value)
elif (value == 10-7):
print(value - 1)
elif (value == 10+4):
print(value - 2)
elif (value == 10//5):
print(value + 1)
Give the output of the following code snippet:
List = [1,2,4,5.5,7,8.25]
Result = 0
List.remove(5.25)
for value in List:
Result += value
print(Result)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","a+")
file2 = open("Test2.txt","r+")
file3 = open("Test3.txt","w+")
string = file.read()
file3.seek(0,2)
file3.write(string)
string = file2.read()
file3.seek(0,2)
file3.write(string)
val = file3.tell()
file.close()
file2.close()
file3.close()
print (val)
Which is the single argument accepted by all instance methods?
Give the output of the following code snippet:
var = 1
while (var == 10):
if( var < 10):
continue
var += 2
else:
var -= 2
print(var)
Give the output of the following code snippet :
value = 5
if(value == (10/3)):
if(value > 0):
value -= 1
print(value)
if (value == 10-4):
print(value + 1)
elif (value == 10/2):
print(value - 2)
Give the output of the following code snippet:
string = "Hello World"
Result = string.split()[1]
print(Result)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' , 'Test2.txt' contains the string ' Green Yellow' and 'Test3.txt' contains the string ' Black White'.
file = open("Test.txt","a+")
file2 = open("Test3.txt","w+")
string = file.read()
file2.seek(1,0)
file2.write(string)
string1 = file2.read(10)
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet : Assume the input given in 11.
try :
value = int(input("Enter value:"))
except ValueError:
print("Invalid")
else :
if(value %2 == 0 ):
print(value)
else :
print(0)
Which of the following statements is true regarding run time errors?
Give the output of the following code snippet:
var = 0
string = "SourceLENS"
for Arg in string:
if(Arg == 'o' or Arg == 's'):
var += 2
elif (var != 1):
var -=1
print(var)
What are some advantages of using IDLE over command line version of Python?
Give the output of the following code snippet in the python shell window:
>>> var = 10
>>> if ( var == 20 or var == 10);
print(100)
Give the output of the following code snippet : Assume the input given in 0.0
try :
value =(input("Enter value from 1 to 50:"))
except:
print("Invalid")
else :
if(value > 0 ) and (value <= 50):
print(value)
else :
print(0)
Give the output of the following code snippet:
var = 0
string = "Hello World"
for Arg in string:
if(Arg == 'o' or Arg != 'l'):
var += 2
else :
var -=1
print(var)
Which attribute can be used to obtain a listing of the individual paths for the system?
Give the output of the following code snippet:
List = ["Hello","World"]*2 + ["World"]* 2
Result = 0
List.remove("Hello")
for value in List[3]:
Result += 2
if(value == 'o'):
Result -= 3
print(Result)
Give the output of the following code snippet:
class MyClass:
def __init__(self, *args):
self.Input = args
def __add__(self, Other):
Output = MyClass()
Output.Input = self.Input - Other.Input
return Output
def __str__(self):
Output = ""
for Item in self.Input:
Output += Item
Output += " "
return Output
Value1 = MyClass("Red", "Green")
Value2 = MyClass("Blue", "Purple")
Value3 = Value1 - Value2
print("{0} + {1} = {2}".format(Value1, Value2, Value3))
Which attribute provides the name and location of the cached file that is associated with a module?
Give the output of the following code snippet:
class MyClass:
def __init__(self, *args):
self.Input = args
def __add__(self, Other):
Output = MyClass()
Output.Input = self + Other
return Output
def __str__(self):
Output = ""
for Item in self.Input:
Output += Item
Output += " "
return Output
Value1 = MyClass("Red", "Green")
Value2 = MyClass("Blue", "Purple")
Value3 = Value1 + Value2
print("{0} + {1} = {2}".format(Value1, Value2, Value3))
Give the output of the following code snippet:
class MyClass:
Sum = 0
def Calc(self,Val1 = 10, Val2=20):
Sum = Val1 * Val2/10
print(Sum)
MyExp = MyClass()
MyExp.Calc(30,40)
Give the output of the following code snippet :
value = 3
if(value == (10//2)):
print(value)
elif (value == 10//3):
print(value - 1)
elif (value == 10//4):
print(value - 2)
elif (value == 10//5):
print(value + 1)
Give the output of the following code snippet : The contents of the file 'Test.txt' is a string 'Red Blue' and 'Test2.txt' contains the string ' Green Yellow'.
file = open("Test.txt","w+")
file2 = open("Test2.txt","w")
file.seek(5,0)
string = file.read()
file2.write(string)
string = file2.tell()
file.close()
file2.close()
print (string)
Give the output of the following code snippet :
value = 10
if(value == 10//4 or 10//2):
else:
print(value + 10)
Give the output of the following code snippet:
string = "This is a test program that is to test string functions"
Result = string.endswith("functions")
print(Result)
Which is the value generally returned by the _initializing_ module which determines if the module is in the process of initializing itself?
Give the output of the following code snippet:
class MyClass:
def __init__(self,Age,Name="John"):
self.Name = Name
self.Age = Age
def GetName(self):
return self.Name
def SetName(self, Name):
self.Name = Name
def GetAge(self):
return self.Age
def SetAge(self, Age):
self.Age = Age + 10
def __str__(self):
return "{0} is aged {1}.".format(self.Name,self.Age)
JohnRecord = MyClass(50)
AnnaRecord = MyClass("Amy", 44)
print(JohnRecord)
Give the output of the following code snippet in the python shell window:
>>> if var == 0 :
print("Hello World")
Which of the following is an add-on to the elementtree library that makes working with XML data more efficient and faster?
Give the output of the following code snippet:
List = [1,2,'Three',4.5]
print((List[1:1] +(List[2:3]))[3])
Every python command has __________ associated with it.
Give the output of the following code snippet:
var = 0
string = "Hello"
for Arg in string:
if(Arg == 'h'):
var +=2
elif (var == 1):
var -=1
break
print(var)
Give the output of the following code snippet in the python shell window:
>>> def Test(Arg = 6):
Arg **=3
Arg /=2
print(Arg)
>>> Test()