Anjeev Singh Academy

Anjeev Singh Academy

50+ Find the output of Python Code important questions

Find the output of the given Python Code
Important Interview Questions (Set-1)


Que 1. Find the output of the given python code.

L1 = [500, 800, 600, 200, 900]
START = 1
SUM = 0
for C in range(START,4):
     SUM = SUM + L1[C]
     print(C,":",SUM)
     SUM = SUM + L1[0]*10
	 print(SUM)

ANSWER:

1 : 800
5800
2 : 6400
11400
3 : 11600
16600


Que 2. Select the correct output of the given python code.

a = "Year 2022 at All the best"
a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)

(a) Year . 0. at All the best
(b) Year 0. at All the best
(c) Year . 022. at All the best
(d) Year . 0. at all the best

ANSWER: (a) Year . 0. at All the best


Que 3. Write the output of the given python code.

>>> myexam="@@CBSE Examination 2022@@"
>>> print(myexam[::-2])

ANSWER:

@20 otnmx SC@


Que 4. Write the output of the given python code.

my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())

ANSWER:

dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])


Que 5. Find and write the output of the following python code:

for Name in ['Jayes', 'Ramya', 'Taruna', 'Suraj'] :
    print (Name)
    if Name[0] == 'T' :
        break
    else :
        print ('Finished!')
print ('Got it!')

ANSWER:

Jayes
Finished!
Ramya
Finished!
Taruna
Got it!


Que 6. Predict the output of the Python code given below:

def Diff(N1, N2):
       if N1>N2:
               return N1-N2
       else:
               return N2-N1

NUM = [10,23,14,54,32]
for CNT in range (4,0,-1):
      A = NUM[CNT]
      B = NUM[CNT-1]

print(Diff(A,B), '#',  end = ' ')

ANSWER:

22 # 40 # 9 # 13 #


Que 7. Predict the output of the Python code given below:

tuple1 = (11, 22, 33, 44, 55 ,66)
list1 = list(tuple1)
new_list = []
for i in list1:
      if i%2==0:
               new_list.append(i)

new_tuple = tuple(new_list)

print(new_tuple)

ANSWER:

(22, 44, 66)


Que 8. Write the output of the code given below:

p=5
def sum(q,r=2):
      global p
      p = r + q ** 2
      print(p, end= '#')

a = 10
b = 5
sum(a, b)
sum(r = 5, q = 1)

ANSWER:

105#6#


Que 9. Write the output of the code given below:

s = "welcome2cs"
n = len(s)
m = ""
for i in range(0, n):
      if (s[i] >= 'a' and s[i] <= 'm'):
              m = m + s[i].upper()
      elif (s[i] >= 'n' and s[i] <= 'z'):
              m = m +s[i-1]
      elif (s[i].isupper()):
              m = m + s[i].lower()
      else:
              m = m +'&'
print(m)

ANSWER:

sELCcME&Cc


Que 10. Predict the output of the given Python code :

x = "apple, pear, peach"
y = x.split(", ")
for z in y :
   print(z)

ANSWER:

apple
pear
peach


Que 11. Predict the output of the given Python code :

x = "apple, pear, peach, banana, grapes"
y = x.split(", ")
for z in y :
       if z > 'f':
             print(z.upper())  
       else:
             print(z)

ANSWER:

apple
PEAR
PEACH
banana
GRAPES


Que 12. Predict the output of the given Python code :

tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
print (tup1 [3:7:2])

a. (40,50,60,70,80)
b. (40,50,60,70)
c. [40,60]
d. (40,60)

ANSWER:

d. (40,60)


Que 13. What is the output of the given Python code :

T=(100)
print(T*2)

a. Syntax error
b. (200,)
c. 200
d. (100,100)

ANSWER:

c. 200


Que 14. Suppose the content of ‘Myfile.txt’ is:

Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky

What will be the output of the following code?

myfile = open("Myfile.txt")
data = myfile.readlines()
print(len(data))
myfile.close()

a. 3
b. 4
c. 5
d. 6

ANSWER:

b. 4


Que 15. Identify the output of the following Python statement :

x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)

a. 12.0
b. 13.0
c. 14.0
d. 15.0

ANSWER:

d. 15.0


Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top