0
what is the output of the program mentioned in the question.
Fill in the blanks to create a loop that increments the value of x by 2 and prints the even values. x = 0 while x <=20: print(x) x += 2 NOTE : I am not getting even values after executing the program . Instead i am getting all zeros as the output
4 Réponses
+ 1
Indent x += 2 to be within your while loop
+ 1
thanks guys
0
mallikarjun 068 I know u got the answer but the reason behind getting 0 is inside the while loop u r the checking the condition X<=20 and if this condition is true then the X value will be printed .In python we have indentation of 4 spaces . And outside the loop the value won't get update .
Syntax :-
Intialization:- X=0
Condition:- while X<=20:
Now to put this condition to the statement
It should be inside of while loop
X+=2 is outside the while loop so it is not changing
Syntax:-
While condition:
Statement 1
Statement 2
Outside the loop while condition will no follow here