python basic training loop

1, using input while loop 1234568910

n = 1
while n < 11:
    if n == 7:
        pass
    else:
        print(n)
    n = n + 1

2, find all the numbers from 1 to 100 and

n = 1
s = 0
while n < 101:
    s = s + n
    n = n + 1
print(s)

3, the output of all the odd 1-100

n = 1
while n < 101:
    temp = n % 2
    if temp == 1:
        print(n)
    else:
        pass
    n = n + 1

4, the output of all the even-numbered 1-100

n = 1
while n < 101:
    temp = n % 2
    if temp == 0:
        print(n)
    else:
        pass
    n = n + 1

5, find all the numbers and 1-2 + 3-4 + 5 ... 99

n = 1
s = 0
while n < 101:
    temp = n % 2
    if temp == 0:
        s = s - n
    else:
        s = s + n
    n = n + 1
print(s)

6, infinite loop

the while . 1. 1 == :
     Print ( ' Hello ' )

7, user login (three chances to retry)

= COUNT 0
 the while COUNT <. 3 : 
    User = INPUT ( " >>> " ) 
    pwd = INPUT ( " >>> " )
     IF User == ' Alex '  and pwd == ' 123 ' :
         Print ( ' Welcome ' )
         BREAK 
    the else :
         Print ( ' user name or password is wrong ' ) 
    COUNT = COUNT +. 1

 

Guess you like

Origin www.cnblogs.com/Wangzui1127/p/11484364.html