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

18th May 2020, 7:29 AM
Ummadisetty . Lakshmi Venkata Mallikarjuna
Ummadisetty . Lakshmi Venkata Mallikarjuna - avatar
3 odpowiedzi
+ 1
Indent x += 2 to be within your while loop
18th May 2020, 7:32 AM
Slick
Slick - avatar
+ 1
thanks guys
19th May 2020, 6:20 AM
Ummadisetty . Lakshmi Venkata Mallikarjuna
Ummadisetty . Lakshmi Venkata Mallikarjuna - avatar
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
18th May 2020, 10:25 AM
Priyal Vyas
Priyal Vyas - avatar