What will be the output of the following Python code
What will be the output of the following Python code
Q3. You are writing a Python program to read two int values from the
keyboard and print the sum.
x=input('Enter First Number:')
y=input('Enter Second Number:')
#Line-1 Which of the following code we have to write at Line-1 to print
sum of given numbers? ]
#A) print('The Result:'+(int(x)+int(y)))
B) print('The Result:'+(int(x+y)))
C) print('The Result:'+str(int(x)+int(y))) *
D) print('The Result:'+str(int(x+y)))
Q5. You are writing a Python program. You required to handle data types
properly. Consider the code segment:
a=10+20
b='10'+'20'
c='10'*3
Identify the types of a,b and c? ]
#A) a is of int type,b is of str type and c is of str type
B) a is of int type,b is of str type and c is of int type
C) a is of int type,b is of int type and c is of int type
D) a is of int type ,b and c are invalid declarations
Q8. You are developing a python application for your company. A list
named employees contains 500 employee names.
In which cases we will get IndexError while accessing employee data? ]
A) employees[1:1000]
B) employees[-10:10]
C) employees[0:501]
#D) None of the above
n1=[10,20,30,40,50]
n2=[10,20,30,40,50]
print(n1 is n2)
print(n1 == n2)
n1=n2
print(n1 is n2)
print(n1 == n2)
What is the result?
A) FalseFalseTrueTrue
B) FalseTrueFalseTrue
C) TrueFalseTrueFalse
#D) FalseTrueTrueTrue*
numbers=[10,20,30,40,50]
alphabets=['a','b','c','d','e']
print( numbers is alphabets)
print( numbers == alphabets)
numbers=alphabets
print( numbers is alphabets)
print( numbers == alphabets)
a=15
b=5
print(a/b)
What is the result ?
A) 3
#B) 3.0
C) 0
D) 0.0
a=21
b=6
print(a/b)
print(a//b)
print(a%b)
What is the result?
A)3,3,3
#B)3.5,3,3
C)3.0,3,3
D)3.5,3.5,3
Q22.
a=bool(0)
b=bool(3) c=bool(0.5) d=bool(0.0) Which variables represent True? ]
- A) a,b
- B) b,c
- D) d,a
- E) All Variables
Q30.
subjects=['java','python','sap']
more_subjects=['java','python','sap']
extra_subjects=more_subjects
In which cases True will be printed to the console? ]
- A) print(extra_subjects is more_subjects)
- B) print(subjects is more_subjects)
- C) print(subjects is extra_subjects)
- D) print(subjects == extra_subjects)
Q32. Which of the following code snippet will produce the output:
Boy Cat Dog ]
- A)l=['Apple','Boy','Cat','Dog']for x in l: if len(x) == 3: print(x)
- B)l=['Apple','Boy','Cat','Dog']for x in l: if len(x) != 3: print(x)
- C)l=['Apple','Boy','Cat','Dog']for x in l: print(x)
- D)l=['Apple','Boy','Cat','Dog']l1=l[1:]for x in l1: print(x)
Q45. In which of the following cases, True will be printed to the console
? ]
- A)a=45b=45print(a is not b)
- B)s1='The Python Course's2='The Python Course'.upper()print(s1 is s2)
- C)x=[1,2,3]y=[1,2,3]print(x is y)
- D)print('r' in 'durga')
- E)print('is' in 'This IS a Fake News')
Q53. In which of the following cases we will get <class 'int'> as output?
]
- A)x=47.0print(type(x))
- B)x='47'print(type(x))
- C)x=10+20jprint(type(x))
- D)x=2**2**2print(type(x))
Q55. Which of the following string declarations spans more than one line
and considers whitespace properly when the string is printed to the
console? ]
- A) s1='durga software solutions'
- B) s1="durga software solutions"
- C) s1='durga\n software\n solutions'
- D) s1='''durga software solutions'''
Q56)
Consider the following code:
print(type(input('Enter some value:'))) if we enter 10 and 10.0
individually for every run what is the output? ]
- A)<class 'str'><class 'str'>
- B)<class 'int'><class 'float'>
- C)<class 'int'><class 'int'>
- D)<class 'float'><class 'float'>
Q57)
Consider the following code:
print(type(eval(input('Enter some value:')))) if we enter 10 and 10.0
individually for every run what is the output? ]
- A)<class 'str'><class 'str'>
- B)<class 'int'><class 'float'>
- C)<class 'int'><class 'int'>
- D)<class 'float'><class 'float'>
Q61)
x='TEXT'
which line of the code will assign 'TT' to the output? ]
- A) output=x[0]+x[2]
- B) output=x[1]+x[1]
- C) output=x[0]+x[-1]
- D) output=x[1]+x[4]
l1=['sunny','bunny','chinny','vinny']
l2=['sunny','bunny','chinny','vinny'] print(l1 is not l2) print(l1 != l2)
l1=l2 print(l1 is not l2) print(l1 != l2) What is the result? ]
- A)TrueTrueFalseFalse
- B)TrueFalseTrueFalse
- C)TrueFalseFalseTrue
- D)TrueFalseFalseFalse
l1=['sunny','bunny','chinny','vinny']
l2=['sunny','bunny','chinny','vinny'] print(l1 is l2) print(l1 == l2)
l1=l2 print(l1 is l2) print(l1 == l2) What is the result? ]
- A)FalseTrueTrueTrue
- B)FalseFalseTrueTrue
- C)FalseTrueFalseTrue
- D)FalseTrueTrueFalse
v1 = 1 v2 = 0 v1 = v1 ^ v2 v2 = v1 ^ v2 v1 = v1 ^ v2 print(v1) What is
the result? ]
- A) 0
- B) 1
- C) 2
- D) 3
a=['a','b','c','d']
for i in a:
a.append(i.upper())
print(a)
What is the result? ]
- A) ['a','b','c','d']
- B) ['A','B','C','D']
- C) SyntaxError
- D) MemoryError thrown at runtime
result=str(bool(1) + float(10)/float(2))
print(result)
What is the output? ]
- A) SyntaxError
- B) TypeError
- C) 6
- D) 6.0
s='DURGA SOFT'
Which of the following lines will assign 9 to variable result? ]
- A) result = len(s)
- B) result = len(s.lstrip())
- C) result = len(s.rstrip())
- D) result = len(s.strip())
- E) result = len(s.replace(' ',''))
Q71. We are developing a python program, where user has to enter number
of items, which should be int type.Even user enter decimal value, it
should be treated as int type only. Which of the fllowing code segment
meets our requirement? ]
- A. n = input("Enter The Number Of Items?")
- B. n = float(input("Enter The Number Of Items?"))
- C. n = str(input("Enter The Number Of Items?"))
- D. n = int(float(input("Enter The Number Of Items?")))
You develop a Python application for your company. You required to accept
input from the user and print that information to the user screen.
Q72. If the user enters 12345 as input,Which of the following code will
print 12346 to the console? ]
- A)count=input('Enter count value:')print(count+1)
- B)count=input('Enter count value:')print(int(count)+1)
- C)count=eval(input('Enter count value:'))print(count+1)
- D)count=int(input('Enter count value:'))print(count+1)
From sys module, by using which variable we can access command line
arguments? ]
- A) argv
- B) args
- C) argsv
- D) arguments
Q76.
Consider the following code:
numbers=[0,1,2,3,4,5,6,7,8,9]
index=0
while (index<10) #Line-1
print(numbers[index])
if numbers(index) = 6 #Line-2
break
else:
index += 1
To print 0 to 6,which changes we have to perform in the above code? ]
- A) Line-1 should be replaced with while(index<10):
- B) Line-2 should be replaced with if numbers[index]==6:
- C) Line-2 should be replaced with if numbers[index]=6:
- D) Line-1 should be replaced with while(index>0):
def my_list(x):
lst.append(a)
return lst
my_list('chicken')
my_list('mutton')
print(my_list('fish'))
to print the following to the console ['chicken','mutton','fish'] x
should be replaced with ]
- A)a,lst=[]
- B)a,lst=()
- C)a,lst={}
- D)a,lst=None
def f1(x=0,y=0):
return x+y
Which of the following method calls are valid? ]
- A) f1()
- B) f1('10','20')
- C) f1(10)
- D) f1('10')
def f1(x=0,y=0):
return x*y
Which of the following method calls are valid? ]
- A) f1()
- B) f1('10','20')
- C) f1(10)
- D) f1('10')
def calculate(amount=6,factor=3):
if amount>6:
return amount*factor
else:
return amount*factor*2
Which of the following function calls returns 30 ]
- A) calculate()
- B) calculate(10)
- C) calculate(5,2)
- D) calculate(1)
for i in range(7):
print(fib_seq(i),end=',')
What is the result? ]
- A) 0,1,1,2,3,5,8,
- B) 0,1,2,4,8,16,32
- C) 0,1,0,2,0,4,0,
- D) None of these
Q86.You are writing code that generates a random integer with a minimum
value of 5 and maximum value of 11. Which of the following 2 functions we
required to use? ]
- A. random.randint(5,12)
- B. random.randint(5,11)
- C. random.randrange(5,12,1)
- D. random.randrange(5,11,1)
Q92 You want to add comments to your code so that other team members can
understand it.
What should you do? ]
- A. Place the comments after the #sign on any line
- B. Place the comments after the last line of the code separated by a
blank line
- C. Place the comments before the first line of code separated by a
blank line
- D. Place the comments inside parentheses anywhere
print( 0 or 50)
print( 0 and 50)
What is the result? ]
- A) True,False
- B)False,True
- C)0,50
- D)50,0
print(bool(0))
print(bool(50))
What is the result? ]
- A)False,True
- B)True,True
- C)False,False
- D)True,False
l1 = [10,20]
l2= [30,40]
l3= l1+l2
l4=l3*2
print(l4)
What is the result? ]
- A) [10, 20, 30, 40, 10, 20, 30, 40]
- B) [20, 40, 60, 80]
- C) [10, 20, 30, 40]
- D) None of these
Q101. The Value must print right alined in a column of 10 spaces wide
with upto one digit after decimal point. Which of the following code will
meet this requirement. ]
- A. print('Value:{:10.1f}.'.format(1.45678))
- B. print('Value:{:<10.1f}.'.format(1.45678))
- C. print('Value:{10:.1f}.'.format(1.45678))
- D. print('Value:{10:.1f}.'.format(1.45678))
Q9.
Consider the code
try: print('try') print(10/0) except: print('except') else:
print('else') finally: print('finally') What is the result? ]
- A)trye,xceptelse,finally
- B)try,else,finally
- C)try,except,finally
- D)try,finally
a=10 b=0 try: print(a/b) Which of the following except block print the
name of exception which is raised,i.e exception class name? ]
- A)except ZeroDivisionError as e: print('Exception
Type:',e.__class__.__name__)
- B)except ZeroDivisionError as e: print('Exception
Type:',type(e).__name__)
- C)except ZeroDivisionError as e: print('Exception Type:',e)
- D) All of these
Q20. Which of the following is valid way of creating our own custom
exception? ]
- A)class MyException: pass
- B) class MyException(): pass
- C)class MyException(Exception): pass
- D) It is not possible to define custom exceptions in python
You are writing an application that uses the sqrt function.The program
must reference the function using the name sq.
Which of the following import statement required to use? ]
- A) import math.sqrt as sq
- B) import sqrt from math as sq
- C) from math import sqrt as sq
- D) from math.sqrt as sq