Life is short, I will be happy to learn Python! 4. The exercises

1, using input while loop 1234568910

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

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 == 0:
        pass
    else:
        print(n)
    n = n + 1

print('----end----')

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

print('----end----')

5, user login (three chances to retry)

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

6, the required number of 1-2 + 3-4 + 5 ... 99 and all

. 1 = n- 
S = 0 # S is the sum before all 
the while n-<100 : 
    TEMP = n-2%
     IF TEMP == 0: 
        S = S - n-    
     the else : 
        S = S + n-             
    n- = n-+. 1
 Print (S )

Guess you like

Origin www.cnblogs.com/ntgale/p/12092742.html