博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第一天作业
阅读量:6943 次
发布时间:2019-06-27

本文共 1401 字,大约阅读时间需要 4 分钟。

1.求1-100的总和

1 count = 02 int = 03 while count < 100:4     count += 15     #print(count)6     int += count7     print(int)

2.使用while循环输出1 2 3 4 5 6 8 9 10

1 count = 02 while count < 10:3     count += 14     if count == 7:5         continue #到循环首,不执行下方代码6     print(count)
1 count = 02 while count < 10:3     count += 14     if count == 7:5         pass #跳过6     else:7         print(count)

3.取奇数偶数

count = 0while count < 100:    count += 1    if count % 2 == 0:        print('偶数:'+  str(count))    else:        #pass        print('奇数:'+  str(count))
count = 1while count < 100:    print(count)    count += 2

 4.1-2+3-4+5-6。。。。99的总和

sum = 0count = 0while count < 99:    count += 1    #print(count)    if count % 2 == 0:        sum -= count #如果为偶数就减    else:        sum += count #如果为奇数就+print(sum)#最后结果为50

5.3次机会猜数字游戏

print('接下来我们进行一个猜数字的游戏')print('你共有3次机会,猜出我心中所想的1-10其中一个')count = 0while count < 3:    ni = int(input('请输入1-10其中一个数字:'))    if ni == 8:        print('恭喜你猜对了!')        break    else:        print('猜错了!你还有' + str(2-count) + '次机会')    count += 1
count = 0while count < 3:    username = input('请输入账号:')    password = input('请输入密码:')    if username == '陈俊' and password == '123':        print('登录成功!')        break    elif count == 2:        print('错误次数超过3次!')    else:        print('登录失败,请检查!你还有' + str(2-count) + '次输入机会!')    count += 1

 

转载于:https://www.cnblogs.com/chengoudan/p/10359580.html

你可能感兴趣的文章
ORALCE存储之ROWID
查看>>
[php]php设计模式 Composite (组合模式)
查看>>
VBA之四----给程序自动加行号
查看>>
Windows 下 Nginx + PHP5 的安装与配置
查看>>
【技术贴】所有好友的QQ空间都打不开进不去的超简单解决办法!
查看>>
这种写法用过没:string.Format("{0,-10}", 8)
查看>>
有关在SharePoint Server中Infopath表单无法呈现的问题及解决方案
查看>>
HDU-1572 下沙小面的(2) DFS
查看>>
Silverlight3.0正式版(Silverlight3_Tools)离线安装
查看>>
微博营销,究竟该怎么做?(实战系列四:活动篇)
查看>>
Sharepoint学习笔记—Ribbon系列-- 1. Ribbon的架构
查看>>
交换机与路由器的区别
查看>>
对${ZSH_VERSION+set}的验证
查看>>
Struts2和Spring3 MVC的区别说明
查看>>
掌握这些电脑知识,你会玩得很无耻
查看>>
admob 广告增加
查看>>
客户/服务器程序设计范式
查看>>
由一个Xml序列化操作看mscorlib.dll 2.0、4.0 String的Trim方法实现
查看>>
Solr拼写检查(spellCheck)配置和使用
查看>>
javascript 中cookie的存储,获取cookie,删除cookie的方法
查看>>