0% found this document useful (0 votes)
39 views6 pages

Python Code Output Analysis

Uploaded by

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

Python Code Output Analysis

Uploaded by

mailtoanbu2001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

PYTHON

1. What could be the possible output of the following code?

digits = [11, 32, 23, 54, 75, 46, 70]

n=7

required = True a) True

for digit in digits: b) False

if n <= digit: c) Syntax Error

required = False e) None of the above


break Answer : c) Syntax error

print (required)

2. What could be the possible output of the following code?

digits = [

a)True
required = b) False

C) Syntax error
digit digits:

n <= digit: d) None of the above

required = Answer: b) False

(required)

3. What is the output of the following code?

(time str): a) [44614, 17772, 185556, 255]

hours, minutes, seconds = (int, time_str.split(':'))


total_seconds = hours * + minu * 60 + seconds b) [12 hours 23 minutes 34 seconds]

total_seconds
ores Secon c) [4 hours 56 minutes 12 seconos]

d) [23 hours 45 minutes 56 seconds]

[to_seconds(time) time in times]

(new_list)

Answer: a) [44614, 17772, 185556, 255]

4. what will be the output of the following code?

a) Inside loop b) Inside loop


Inside loop Inside loop
Else block
count +- c) Inside loop d) None of these
count == =: Else block

Answer: b) Inside loop


Inside loop

5. Which of the following is not a valid built-in method for type conversion in
Python?
a) Int

b) float

c) list

d) char

Answer :d) char

6. Find the following code snippet?

a)0123
b)012
c)01234

d)12

Answer: b) 012

7. What is the space complexity of dictionary in python?


a) O(n?)

b) O(log n)

c) O(n)

d) O(n log n)

Answer: c) O(n)

8. what is the purpose of loop in python?

a) To define functions in Python.

b) To handle exceptions and errors in Python.

c) To repeating a block of code multiple times.

d) To perform mathematical operations in Python.


Answer: c) To repeating a block of code multiple times

9. what will be the output of the given code?

data = , &, 2, 2;
result a) 105
_ b) 120
(data)):
(i +i, (data)): c) 65
data[i] > data[j]:
ataLli ataLlj d) 75

result += data[j]

result += data[i] Answer: c) 65

(result)

10. Encapsulation as a feature is available with


a) Procedural Programming

b) Structured Programming

c) Object Oriented Programming

d) None of these

Answer: c) Object Oriented Programming

11. Which of the following objects is/are immutable in Python?


a) String

b) List

c) Tuple

d) String and tuple

Answer: d) String and tuple

12. A class can be defined as

a) an entity consisting of some values

b) A structure that defines methods only

c) A structure that defines the data only

d) the structure that contains the data & the methods

Answer: d) the structure that contains the data & the methods

13. which of the following are the paradigms of the programming?


a) Procedural Programming

b) Object Oriented Programming

c)Structured Programming

d) All of the Above


Answer: d) All the Above

14. what is polymorphism?

Answer: programming it refers to methods/functions/operators with the


same name that can be executed on many objects or classes.
15. Find the output of the following snippet?

collections

myqueue = deque(

[Link](i0) Answer: output

myqueue . pop ) myqueue = [1, 2, 3, 4, 5, 6, 7, 8, 9]


[Link](0)

[Link]()

(myqueue)

16. find the output of the following snippet?


for num in range(15,-6,-4):
print (num)
Answer: output is
15
11
7

-1
5

17. Consider a situation where an incorrect value has been inserted into an
environment variable by another developer and you are asked to remove that
variable's value. The variable's name is "NAME". Which option will you choose
from the listed choices in order to complete the given requirement?

a) remove NAME

b) unset NAME

c) export NAME

d) autoremove NAME
Answer: b) unset NAME

18. When the computer is directed to perform an illegal operation by the


program such as dividing a number by zero then the type of error shown is

a) Syntax Error

b) Logical Error

c) Run Time Error

d) zerodivision Error

Answer: c) Run Time Error

19. Which of the following iterative statement execute at least once?


a) for loop

b) while loop

c) do while loop

d) break

Answer: c) do while loop

20. Allocation and Deallocation of the resource required to execute the


program is done by

a) Operating System

b) Compiler

c) Linker

d) Loader

Answer: a) Operating System

21. The correct sequence of the below steps to reverse the ian song
1 Initiate

2. Get the length of the string

3 Start a loop and then swap the position of the array elements
4 Keep the exchanged positions.

5. Print the reversed string.

6. The string which is to be reversed is declared.

Answer: 1, 6, 3, 4, 5, 2.

22. Read the instructions and complete the program

Kalyani, the process in which Python reclaims unused memory blocks at a


periodic interval is termed as

a) Reclamation

b) Compaction

c) Garbage Collection

d) None of the these

Answer: c) Garbage Collection

23. what is the output of the following snippet?


while (true)

// Some code here


if (some condition)

break the loop

a) it will run forever

b) It will run till "some condition" is satisfied

c) It will run only if "some condition" is satisfied

Python Codings:
1) name = input() output:

print ("Hello, " + name) Hello, Doselect

2) a =input(" ") output:

b = input(" ") Do
c= (at" "+b) Select

print(c) Do Select

3) Find the max length of the string


a=int(input())

b=input()

c=input()

d=input()
Max_num=max(len(b),len(c),len(d))

print(Max_num)

You might also like