What did I learn on day1?

   In the past, I used to learn python by myself without the teacher's explanation and without the atmosphere of learning together with my classmates, and my progress was very slow.

After listening carefully on the first day, my memory of the basic part became more profound.

Operation:

Find the sum within 100:

# -*- coding:utf-8 -*- 
sum = 0

count = 1
while count < 101:
sum = sum + count
count = count + 1
print(sum)
Odd numbers within one hundred:
# -*- coding:utf-8 -*-
count = 0
while True:
if count == 100:
break
count = count + 1
if 0 != count % 2:
print(count)
一百以内的偶数:
# -*- coding:utf-8 -*- 
count = 1
while count < 101:
div = count % 2
if div == 0:
print(count)
else:
pass
count = count + 1
to find 1-2+3- Sum of all numbers 4+5 ... 99:
# -*- coding:utf-8 -*- 
count = 1
sum = 0
while count < 100:
div = count % 2
if div == 1:
sum = sum + count
else:
sum = sum - count
count = count + 1
print(sum)
User login (three chances of error):
# -*- coding:utf-8 -*- 
counts = 0
user_list = [{'username':'jack', 'password':'123456' },{'username':'tom', 'password':' 123456'},
{'username':'jieru', 'password':'123456'},{'username':'xiaogang', 'password':'123456'},]

flag = False
for item in user_list:
user = input("Please enter the username:")
passwd = input("Please enter the password:")
if item['username'] == user and item['password'] == passwd:
flag = True
print("Login Success")
break
else:
print("Login failed")
counts = counts + 1
if counts == 3:
print("You have typed the wrong three times, you can't type any more.")
break



Guess you like

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