What will be the output of the following Python code? x = “abcdef” i = “a” while i in x: print(‘i’, end = “ ”)

Question: What will be the output of the following Python code?

x = “abcdef” 

i = “a” 

while i in x: 

    print(‘i’, end = “ ”)


(a) No output 

(b) i i i i i i ... 

(c) a a a a a a... 

(d) a b c d e 

Ans: (b) i i i i i i ... 

Here i i i i i i ... printed continuously because as the value of i or x is not changing, the condition will always evaluate to True. But also here we use a quotation marks on “i”, so here i treated as a string, not like a variable.

Comments

Popular posts from this blog

Diagonal Relationship between Beryllium and Aluminium || Relation between Beryllium and Aluminium

IPL 2023 Season Summary || Moments of IPL 2023

Simple Calculator using Tkinter

Computer science MCQ questions Class 12 Python

Phosphorus and chlorine form two compounds.The first compound contains 22.54% by mass of phosphorus and 77.46% by mass of chlorine. In the second compound the percentages are 14.88 for phosphorus and 85.12 for chlorine. Show that these data are consistent with the law of multiple proportions.