1、使用while循环输入1234568910
 n = 1
while n < 11:
if n == 7:
pass
else:
print(n)
n = n + 1

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

n = 1
s = 0
while n < 101:
s = s + n
n = n + 1 print(s)

3、输出1 - 100内的所有奇数
n = 1
while n < 101:
temp = n % 2
if temp == 0:
pass
else:
print(n)
n = n + 1 print('----end----')

4、输出1 - 100内的所有偶数
n = 1
while n < 101:
temp = n % 2
if temp == 0:
print(n)
else:
pass
n = n + 1 print('----end----')

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

n = 1
s = 0 # s是之前所有数的总和
while n < 100:
temp = n % 2
if temp == 0:
s = s - n
else:
s = s + n
n = n + 1 print(s)
6、设计登录小程序,有三次机会
import datetime
username = "keys"
password = ""
no = 2
while no >= 0:
input_name = input("请输入你的账号:")
input_pswd = input("请输入你的密码:")
if username == input_name and password == input_pswd:
print("恭喜您"+username+"登录成功,今天是{}".format(datetime.datetime.today()))
break
elif input_name == "" or input_pswd == "":
print("用户名或密码不能为空,请重新输入")
print("您还有"+str(no)+"次机会!!!")
else:
if username != input_pswd or password != input_pswd:
print("\n账号或密码错误,请重新输入")
print("温馨提示,您还有"+str(no)+"次机会")
else:
print("您的次数已用完。")
no = no -1

 

python基础循环的更多相关文章

  1. python基础-循环

    循环 循环 要计算1+2+3,我们可以直接写表达式: >>> 1 + 2 + 3 6 要计算1+2+3+...+10,勉强也能写出来. 但是,要计算1+2+3+...+10000,直 ...

  2. python基础-循环语句(5)

    一.循环语句介绍 一般情况下,需要多次重复执行的代码,都可以用循环的方式来完成 循环不是必须要使用的,但是为了提高代码的重复使用率,所以有经验的开发者都会采用循环 二.常见的循环形式 while循环 ...

  3. python基础——循环(for,while,break,continue)

    for while . break:退出循环 continue:退出本次循环 例子 for i range(0,101,2): print(i) --------------------------- ...

  4. python基础-循环语句for\嵌套循环

    for循环格式: for index in range(0,3):#等同于range(3),取0\1\2 print(index) index = 0 starnames = ['xr1','xr2' ...

  5. python基础-循环语句while

    循环语句:while\for\嵌套 循环控制语句:break\continue break:跳出整个循环,不会再继续循环下去 continue:跳出本次循环,继续下一次循环 while循环: coun ...

  6. python基础 — 循环重新输入

    后续完善各种循环案例 while True: try: str_num = input('input a number:') num = float(str_num) print("你输入的 ...

  7. Python基础——循环语句、条件语句、函数、类

    注:运行环境  Python3 1.循环语句 (1)for循环 注:for i in range(a, b):  #从a循环至b-1 for i in range(n):      #从0循环至n-1 ...

  8. python基础循环语句练习

    1.使用while循环输入 1 2 3 4 5 6     8 9 10 n = 1 while n < 11: if n == 7: pass else: print(n) n = n + 1 ...

  9. 【原】Python基础-循环语句

    x = 1while x <= 10: print(x) x += 1 password = ""while password != "3213554": ...

随机推荐

  1. centos7 安装percona-toolkit工具包的安装和使用

    一.检查和安装与Perl相关的模块 PT工具是使用Perl语言编写和执行的,所以需要系统中有Perl环境. 依赖包检查命令为: rpm -qa perl-DBI perl-DBD-MySQL perl ...

  2. 把已经安装到C盘的软件完美移动到D盘

    背景信息 今天早上在安装软件的时候发现C盘爆满,只剩下最后10G了.而我要安装的玩意儿必须装到C盘. 靠清理垃圾文件来解决并不是一个好方法,实际上通常垃圾文件占用很少,而且就算清理了,也还会再出现. ...

  3. centos7 设置系统默认启动的界面

    系统默认 以某种方式启动 使用systemd创建符号链接指向默认运行级别. 修改方法为:在root下 1.首先删除已经存在的符号链接rm /etc/systemd/system/default.tar ...

  4. win7 64 位 + vs2015 + opencv3.2

    下载OpenCv_3.2_vc14 链接:http://pan.baidu.com/s/1eSBu1NG 密码:104g 1.下载好后,进行解压到自己指定的目录: 解压后可以得到: 2.添加环境变量 ...

  5. Unable to complete the scan for annotations for web application [/wrs] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies.

    tomcat启动报错:Jul 20, 2018 11:48:37 AM org.apache.catalina.core.ContainerBase addChildInternalSEVERE: C ...

  6. 01 Python 逻辑运算

    #基本运算符 #and or not #优先级 ()>not>and>or #and or not print(2>1 and 1<4 or 2<3 and 9&g ...

  7. python解决open()函数、xlrd.open_workbook()函数文件名包含中文,sheet名包含中文报错的问题

    问题现象: 1.使用open()函数.xlrd.open_workbook()函数打开文件,文件名若包含中文,会报错找不到这个文件或目录. 2.获取sheet时若包含中文,也会报错. #打开文件 fi ...

  8. leetcode155

    public class MinStack { Stack<int> S = new Stack<int>(); /** initialize your data struct ...

  9. @ResponseBody 与 response.getWriter.write

    @responseBody注解的使用 1. @responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通 ...

  10. linux查看磁盘大小df命令

    df -h https://www.cnblogs.com/sparkdev/p/9273094.html