While Loop User Input in Python

User Input in While Loop in Python programming is a control flow that reads from user input a sequence and stops reading from user input until the condition is met.

While Loop User Enter value Printing in Descending Order

Program

n = int(input("Enter Value: ")) #user enter value assigning to 'n'.
while n != 0: #checking condition.
    print(n) #printing 'n' value.
    n-=1 #and Subtracting 1.
Output
Enter Value: 13
13
12
11
10
9
8
7
6
5
4
3
2
1

Program While Loop using If Statement

Program

a = 0
while a <= 10: #loop looping from 0 to 10.
    if a > 4 and a < 8: #if 'a' value greeter then 4 And less then 8 then
        print(a) #print 'a' value.
    a = a + 1 #adding 1 to 'a' value.
Output
5
6
7

Program While Loop Password Program

Program

a = ''
while a != "Bilal": #loop stops when 'a' value Equal to 'Bilal'.
    a = input("Please Enter Password: ") #user enter value assigning to 'a'.
print("Password Correct!")
Output
Please Enter Password: Khan
Please Enter Password: abc
Please Enter Password: Admin
Please Enter Password: Bilal
Password Correct!

While Loop Password Another Program
Program

a = ''             #loop stops when 'a' value Equal to 'Bilal' And
while a != "Bilal" and a != "HiLaLs": #'HiLaLs'.
    a = input("Please Enter Password: ") #user enter value assigning to 'a'.
print("Password Correct!")
Output
Please Enter Password: Bilal
Password Correct!