import getpass
#标准库里要加密密码需要导包getpass.但是getpass在pycharm中不好用,需要在命令窗口中输入才管用. _username = "abc"
_password = "abc123"
username = input("username:")
# password = getpass.getpass("password:")
password = input("password:") if _username==username and _password==password:
print("Welcome user {name} login...".format(name=username))
else:
print("invalid username or password")
 age_of_oldboy = 56

 guess_age = int(input("guess age:"))

 if guess_age==age_of_oldboy:
print("yes, you got it.")
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
 age_of_oldboy = 56

 count=0
while True:
if count==3:
break
# print("count:",count)
guess_age = int(input("guess age:")) if guess_age==age_of_oldboy:
print("yes, you got it.")
break
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
count=count+1 #count+=1
if count==3:
print("you have tried too many times! Fuck off!") # 优化后的代码
while count<3:
guess_age = int(input("guess age:")) if guess_age==age_of_oldboy:
print("yes, you got it.")
break
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
count=count+1 #count+=1
else:
print("you have tried too many times! Fuck off!")
 '''
while循环实现
age_of_oldboy = 56 count=0
while True:
if count==3:
break
# print("count:",count)
guess_age = int(input("guess age:")) if guess_age==age_of_oldboy:
print("yes, you got it.")
break
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
count=count+1 #count+=1
if count==3:
print("you have tried too many times! Fuck off!") # 优化后的代码
while count<3:
guess_age = int(input("guess age:")) if guess_age==age_of_oldboy:
print("yes, you got it.")
break
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
count=count+1 #count+=1
else:
print("you have tried too many times! Fuck off!") '''
'''
for i in range(10): #range10其实是从0到9.
print("loop", i)
''' # for循环来实现
age_of_oldboy = 56
for i in range(3):
guess_age = int(input("guess age:"))
if guess_age == age_of_oldboy:
print("yes, you got it")
break
elif guess_age > age_of_oldboy:
print("think smaller")
else:
print("think bigger")
else:
print("you have tried too many times.. fuck off!")
 # 0到9的数字,隔一个打印一个到控制台
for i in range(0,10,2): #括号中的2是步长,不写的话默认是1.若想隔两个打印一uqw,则步长设置为3即可.即for i in range(0,10,3)
print("loop", i)
 # 每错三次不直接跳出,而是问玩家是否要继续
age_of_oldboy = 56 count=0
while True:
if count==3:
break
# print("count:",count)
guess_age = int(input("guess age:")) if guess_age==age_of_oldboy:
print("yes, you got it.")
break
elif guess_age>age_of_oldboy:
print("think smaller")
else:
print("think bigger")
count=count+1 #count+=1
if count==3:
continue_confirm = input('do you want to continue?')
if continue_confirm !='n':
count=0
else:
print("you have tried too many times! Fuck off!")
 # continue的用法: 跳出本次循环,继续下一次循环
for i in range(0,10):
if i<5:
print("loop", i)
else:
continue #跳出本次循环,继续下一次循环
print("hehe...")
 #break:结束当前循环
for i in range(10):
print("-----------------",i)
for j in range(10):
print(j)
if j>5:
break

if_else_while_for的更多相关文章

随机推荐

  1. python 3下基于select模型的事件驱动机制程序

    它的基本原理就是select/epoll这个function会不断的轮询所负责的所有socket,当某个socket有数据到达了,就通知用户进程.它的流程如图: 当用户进程调用了select,那么整个 ...

  2. 深入源码解析类Route

    微软官网对这个类的说明是:提供用于定义路由及获取路由相关信息的属性和方法.这个说明已经很简要的说明了这个类的作用,下面我们就从源码的角度来看看这个类的内部是如何工作的. public class Ro ...

  3. 从小故事来谈nginx负载均衡

    负载均衡 负载均衡是任何一个有一定规模的互联网企业都会考虑的问题,负载方式很多,有依靠硬件实现的,也有依靠软件实现负载的. 今天来聊聊使用软件来负载的方式 你可能听过各自负载的方式,比如常见的ngin ...

  4. Spring Boot 2.0.1 入门教程

    简介 Spring Boot是Spring提供的一套基础配置环境,可以用来快速开发生产环境级别的产品.尤其适合开发微服务架构,省去了不少配置麻烦.比如用到Spring MVC时,只需把spring-b ...

  5. MDF,了解一下

    1.MDF定义 MDF,全称(Measurement Data Format),即测量数据格式,是ASAM(自动化及测量系统标准协会)定义的.MDF的网页https://www.asam.net/st ...

  6. 手把手教你用Jenkins自动发布dotnet core程序

    Jenkins部分 首先,我们要有个Jenkins咯,下载链接:https://jenkins.io/download/ 我们安装官网教程安装好jenkins,安装教程略.... 嗯?不是说好手把手么 ...

  7. 做双网卡绑定_______物理机在双网卡的情况下做多IP绑定

    公司的环境是这样的: 一台物理机需要做双网卡绑定,同时呢,在双网卡绑定的同时还要做多IP. 其实整个过程可以分为两个步骤: 第一个,物理机先做双网卡. 第二个,在bond上做多IP实例. 双网卡绑定的 ...

  8. 对比Cassandra、 Mongodb、CouchDB、Redis、Riak、 Membase、Neo4j、HBase

    转自:http://www.cnblogs.com/alephsoul-alephsoul/archive/2013/04/26/3044630.html 导读:Kristóf Kovács 是一位软 ...

  9. Pydev Console中文提示乱码的问题

    1. 像这样的规则内容请这样处理"\u305d\u3093\u306a\u306b"style unicode string : print str.decode("un ...

  10. 学习spring中遇见的问题

    报错: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nes ...