The first day of python22 (homework)

1. Find the sum of all numbers from 1 to 100

sum = 0
for i in range(101):
    sum = sum + i

print(sum)

 

2. Radix within 1-100

m = 0
while m < 101:
    i = m%2
    if i == 1:
        print(m)
    m += 1

 

3.1-Even within 100

m = 0
while m < 101:
    i = m%2
    if i == 0:
        print(m)
    m += 1

 

 

4. Find the sum of all numbers 1-2+3-4+5 ... 99

n = 0
m = 0
while [1]:
     if 0 == n % 2:
         m = m - n
     else:
         m = m + n
     if n == 100:
         break
     n += 1

print(m)

 

 

5. User login (three false chances)

import sys
user_list = [
    {'username': 'alex', 'password': '123'},
    {'username': 'eric', 'password': '123'},
    {'username': 'tony', 'password': '123'},
    {'username': 'oldboy', 'password': '123'},
]

flag = False
count = 0
while True:
    user = input( " Please enter the user name: " )
    pwd = input( " Please enter your password: " )


    for item in user_list:
            if item['username'] == user and item['password'] == pwd:
                flag = True
             else :
                 pass 
    if flag:
         print ( " Login successful " )
        exit()
    else :
         print ( " Login failed, please log in again " )
        count += 1
         if count == 3 :
             print ( ' You have entered the wrong user password more than 3 times, and you have logged out ' )
            exit()

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325640736&siteId=291194637