Python基础学习之(一)练习
·
Python基础学习之(一)练习
一、使用while循环输入 1 2 3 4 5 6 8 9 10
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/6 下午 10:39
# @File: practice1.py
# @Software: PyCharm
# 使用while循环输入 1 2 3 4 5 6 8 9 10
n = 1
while n < 11:
if n == 7:
n = n+1
print(' ')
continue
print(n)
n = n + 1
print(end='\n')
二、求1-100的所有数的和
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/6 下午 10:49
# @File: practice2.py
# @Software: PyCharm
#求1-100的所有数的和
n = 1
s = 0
while n < 101:
s = s+n
n = n+1
print(s)
三、输出 1-100 内的所有奇数
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/6 下午 10:53
# @File: practice3.py
# @Software: PyCharm
# 输出 1-100 内的所有奇数
n = 1
while n < 101:
if n % 2 == 0:
n = n + 1
continue
print(n)
n = n + 1
print(end='')
四、输出 1-100 内的所有偶数
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/6 下午 11:01
# @File: practice4.py
# @Software: PyCharm
# 输出 1-100 内的所有偶数
n = 1
while n < 101:
if n % 2 != 0:
n = n + 1
continue
print(n)
n = n + 1
print(end='')
五、求1-2+3-4+5 … 99的所有数的和
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/6 下午 11:02
# @File: practice5.py
# @Software: PyCharm
# 求1-2+3-4+5 ... 99的所有数的和
n = 1
s = 0
while n < 100:
if n % 2 != 0:
s = s + n
n = n + 1
continue
else:
s = s - n
n = n + 1
print(s)
print(end='\n')
六、用户登陆(三次机会重试)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time: 2021/5/7 下午 8:04
# @File: practice6.py
# @Software: PyCharm
i = 1
while i < 4:
username = input("请输入用户名:")
pwd = input("请输入密码:")
if username == 'zoey' and pwd == '123456':
print("登录成功!")
break
else:
print("用户名或密码错误!")
i = i + 1
更多推荐



所有评论(0)