1、使用while循环输入 1 2 3 4 5 6     8 9 10

 count = 0
while count <= 9:
count += 1
if count == 7:continue
print(count)

或:

 # 把7换成空格
count = 0
while count < 10:
count += 1
if count == 7:
print(' ')
else:
print(count)
# 不输入空格
count = 0
while count < 10:
count += 1
if count == 7:continue
print(count)
# 用pass
count = 0
while count <= 9:
count += 1
if count == 7:
pass #直接跳过
else:
print(count)

2、求1-100的所有数的和

 count = 0
sum = 0
while count < 100:
count += 1
sum = sum + count
print(sum)

3、输出 1-100 内的所有奇数

 count = 0
while count < 100:
count += 1
if count % 2 == 0:continue
print(count)

或:

# 第一种方法
count = 1
while count < 101:
print(count)
count += 2
# 第二种方法
count = 1
while count < 101:
if count % 2 == 1:
print(count)
count += 1

4、输出 1-100 内的所有偶数

 count = 0
while count < 100:
count += 1
if count % 2 == 1:continue
print(count)

5、求1-2+3-4+5 ... 99的所有数的和

 power = 1
count = 0
sum = 0
while count < 99:
count += 1
power += 1
sum = sum + count*((-1)**power)
print(sum)

或:

 count = 1
sum = 0
while count < 100:
if count % 2 == 0:
sum -= count
else:
sum += count
count += 1
print(sum)

6、用户登陆(三次机会重试)

 user_name = 'admin'
password = 'admin'
count = 0
while count < 3:
count += 1
name = input ('请输入用户名:')
if name == user_name:
pw = input('请输入密码:')
if pw == password:
print('登陆成功')
break
else :print('密码错误!')
if count == 3:print('登陆超过三次!请明天重试。')
else :
print('用户名不存在!')
if count == 3 :print('登陆超过三次!请明天重试。')

或:

 i = 0
while i <3:
username = input('请输入账号:')
password = input('请输入密码:')
if username == 'admin' and password == 'admin':
print('登陆成功')
else:
print('登录失败,请重新登录')
i += 1

python学习之老男孩python全栈第九期_day001作业的更多相关文章

  1. python学习之老男孩python全栈第九期_day002作业

    1. 判断下列逻辑语句的True,False.(1) 1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6Tru ...

  2. python学习之老男孩python全栈第九期_day015作业_老男孩Python全9期练习题(面试真题模拟)

    一. 选择题(32分) 1. python不支持的数据类型有:AA. charB. intC. floatD. list 2. Ex = ‘foo’y = 2print(x + y)A. fooB. ...

  3. python学习之老男孩python全栈第九期_day007作业

    一.关系运算 有如下两个集合,pythons是报名python课程的学员名字集合,linuxs是报名linux课程的学员名字集合pythons={'alex','egon','yuanhao','wu ...

  4. python学习之老男孩python全栈第九期_day001知识点总结

    1. Python2与Python3的区别: Python2:源码不标准,混乱,重复代码太多: Python3:统一标准,去除重复代码. 编码方式: python2的默认编码方式为ASCII码:pyt ...

  5. python学习之老男孩python全栈第九期_day016作业

    1. 请利用filter()过滤出1~100中平方根是整数的数,即结果应该是: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] import math def func( ...

  6. python学习之老男孩python全栈第九期_day004作业

    看代码写结果:1. a=[1,2,3,6,"dfs",100]s=a[-1:]print (s) 结果:[100] 2. s=a[-1:0:-1]print(s) 结果:[100, ...

  7. python学习之老男孩python全栈第九期_day003作业

    1. 有变量name = "aleX leNb" 完成如下操作:(1) 移除 name 变量对应的值两边的空格,并输出处理结果name = ' aleX leNb 'print(n ...

  8. python学习之老男孩python全栈第九期_day014作业

    0. 默写a. 生成器函数获取移动平均值例子: def init(func): def inner(*args,**kwargs): ret = func(*args,**kwargs) ret.__ ...

  9. python学习之老男孩python全栈第九期_day011作业

    1. 编写函数.(函数执行的时间是随机的) import timeimport randomdef random_time(): ''' 执行时间随机的函数 :return: ''' time.sle ...

随机推荐

  1. Vuejs——(8)Vuejs组件的定义

    版权声明:出处http://blog.csdn.net/qq20004604   目录(?)[+]   本篇资料来于官方文档: http://cn.vuejs.org/guide/components ...

  2. 消息中间件——kafka

    1.1.1 什么是消息中间件 消息中间件利用高效可靠的消息传递机制进行平台无关的数据交流,并基于数据通信来进行分布式系统的集成.通过提供消息传递和消息排队模型,它可以在分布式环境下扩展进程间的通信.对 ...

  3. JavaScript中的constructor和继承

    概述 这是我在看JavaScript面向对象编程指南的时候,对constructor和继承的总结. 关于它们的详细知识,可以上网查到,所以我只写那些网上没有的. 内容 constructor的理解 c ...

  4. 使用 Maven 插件将 class(字节码文件),resource(资源文件),lib(依赖的jar包)分开打包

    1. 在pom文件中对各个插件进行配置 <?xml version="1.0" encoding="UTF-8"?> <project xml ...

  5. Spring Boot实现热部署

    在Spring Boot实现代码热部署是一件很简单的事情,代码的修改可以自动部署并重新热启动项目. 引用devtools依赖 <dependency> <groupId>org ...

  6. 21-json pickle shelve XML

    我们把对象从内存中变成可存储或传输的过程称之为序列化 在python中叫picking 在其他语言中也被称之为 serialization marshalling flattening等等 序列化之后 ...

  7. 转载 12步轻松搞定python装饰器

    作者: TypingQuietly 原文链接: https://www.jianshu.com/p/d68c6da1587a 呵呵!作为一名教python的老师,我发现学生们基本上一开始很难搞定pyt ...

  8. iOS-关于缓存【SDImageCache】Image,一直刷新UIImageView内存一直增加问题

    最近做的一个项目,里面有这样一个需求,在一个页面,用一个UIImageView不停的刷新显示图片,图片可能会重复显示:图片是从服务器下载下来的data流,data转UIimage系统的方法: UIIm ...

  9. apache和tomcat的区别和联系

    两者既有联系又有区别,是两个软件,可独立使用,也可整合使用.Apache是web服务器(静态解析,如HTML),本身只支持html,Web服务器专门处理HTTP请求(request),可以通过插件支持 ...

  10. ffmpeg 视频实现各种特效

    直接上命令: //渐入i in.mp4 -vf fade=in:0:90 out.mp4                 //黑白                    i in.mp4 -vf lu ...