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

What does one mean by exothermic and endothermic reactions? Give examples.

NCERT Solutions class 10 Science Chapter 9 || (Heredity and Evolution Solution Class 10 Science Chapter 9 || Heredity and Evolution Solution || Biology || Science ||

Data Mining || Supervised vs. Unsupervised Techniques || Dimensionality Reduction || Partitioning Methods

2.0 gram of a metal burst in oxygen give 3.2 gram of its oxide. 1.42 gram of the same metal heat in steam give 2.27 gram of its oxide which toys shown by this data?

Carbohydrates || Lipids|| Proteins || Vitamins & Minerals || Fats and Oils