day1我学会了什么?

   以前都是自己自学python没有老师的讲解没有同学们一起学习的氛围,自己的进展很慢。

通过第一天认真的听讲,使我对基础部分记忆的更加的深刻了。

作业:

求一百以内的和:

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

count = 1
while count < 101:
sum = sum + count
count = count + 1
print(sum)
一百以内的奇数:
# -*- 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
求1-2+3-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)
用户登录(三次错误机会):
# -*- 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("请输入用户名:")
passwd = input("请输入密码:")
if item['username'] == user and item['password'] == passwd:
flag = True
print("登录成功")
break
else:
print("登录失败")
counts = counts + 1
if counts == 3:
print("您已经输错三次,不能再输入了。")
break



猜你喜欢

转载自www.cnblogs.com/dingyang-python/p/9010143.html