# While loop Problem

while (i<18) :
if (i<5):
print(“You are not eligible for the ride”)
else:
(“You are eligible for the ride”)

Hey I am new learning python. I was practising while loop so came across random code to practice. Can anyone tell how its output will be because The output I am looking for is not in real so can anyone explain what does the code exactly means

A `while` loop means “repeat the following block of code until the condition is not met.” The loop is set to run `while (i < 18)`, but then `i` is overwritten by `i=int(input(“Enter your height:”))`. So any value for height less than 18 will cause the loop to stop once it finishes the current iteration. We can’t see how much of the code is inside that block (use the </> button to add formatting to your posts) but I can’t imagine that’s the intended result.

A `while` loop means “repeat the following block of code until the
condition is not met.” The loop is set to run `while (i < 18)`, but
then `i` is overwritten by `i=int(input(“Enter your height:”))`. So any
value for height less than 18 will cause the loop to stop once it
finishes the current iteration.

To my eye the loop logic is a bit odd, because it at least starts
examining the age (in the `i` variable) and then on subsequent loops
examines the height (because that is what is in the `i` variable then).

Lubna, you will do better to give these distinct vairable names,
example:

`````` age =int(input("Enter your age:"))
while (age <18) :
if (height<5):
``````

and so forth.

Also, it looks like this should be an `if` instead of a `while`. The age
isn’t going to change, so either the `age>=18`, in which case the while
is nver entered (because `age<18` is false) _or `age<18`, in which case
the loop runs forever, because the age won['t get changed.

We can’t see how much of the code is inside that block (use the </>
button to add formatting to your posts) but I can’t imagine that’s the
intended result.

I’m on email, so I get it direct Here it is:

`````` i=int(input("Enter your age:"))
while (i<18) :
if (i<5):
print("You are not eligible for the ride")
else:
("You are eligible for the ride")
``````

Also, indentation is critical in Python. There’s no `end-while` or
`end-if` or curly brackets to mark out where in the logic some code
belongs. It is all indentation. So in the above, this line:

`````` i=int(input("Enter your height:"))
``````

is in the while-loop, but nothing else is because it is not indented
underneath the while.

Also, the `else:` part of your if statement doesn’t do anything. This
line:

`````` ("You are eligible for the ride")
``````

is legal Python, but it just gets evaluated. And then discarded. To see
it printed you need to call print, i.e.:

`````` print("You are eligible for the ride")
``````