- 1

# Need solution

What is the output? x=0 while x<5: x=x+2 print(x) How the answere is 6? Prblem:2 x=0 a=[ ] while x <=3: x*=2 a.append(x) print(a) How the answere is infinite loop? Explain please!

11 Answers

+ 4

Problem 1
X= 0, in first loop x= x+2 = 2, second 2+2;= 4, and third 4+2= 6, then x>5 so while loop breaks. And x is printed.
Problem 2
Your while loop is an infinite loop because perhaps you forgot to increase x, in the loop.

+ 2

No, you are misunderstanding while loop with for loop perhaps or idk. It is straight x= 0+2, 2+2,4+2

+ 1

Problem 1:
The while loop does 3 iterations before exiting, each time adding 2 to x. So 2 + 2 + 2 = 6. Right before the 4th iteration, x < 5 is no longer true, so the loop exits.
Problem 2:
It is an infinite loop because x is always 0, which means x <= 3 is always true. This is because x *= 2 computes 0 * 2 = 0.

+ 1

But while x<5 mean x=0,1,2,3,4
Why just 2+2+2?

+ 1

While loop does not increase the x automatically, it is increasing by 2 because it is in the code 'x = x+2'

+ 1

x increases by 2 each time because of `x = x + 2`. So the x values are not 0, 1, 2, 3.. but 0, 2, 4, 6

+ 1

prloblem 1
If i share what i think about that is
X=0+2, x=2+2
X=1+2, x=3+2
X=2+3, x=5+2
Like that???

0

For problem 1,
X = 4+2 = 6 ( because our condition is x<5 so, lastly we have to consider x = 6 as our final answer.

0

Hello can anyone please tell me how python helpful?

0

Every programming language is important. A decades ago java was the most popular programming language. After that python took place of java. Now python is learning rapidly. You-tube platform is also made by several type of programming languages. Python is one of them. Python's syntex is much easier than java. And why you telling what is the important of python! or how python helpful!
Just simply search on google or youtube to know about python.
Good luck Bushra Saleem

Hot today

What's wrong? :(

1 Votes

Why won't my image display

0 Votes

I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.

2 Votes

How the answer is 50?

0 Votes

Number of Ones ( C++ ) question!

1 Votes