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. PHP变量的定义与相应的数据类型

    在PHP中,变量的定义和C语言定义的方法是类似的,但是在PHP中,变量使用起来就非常灵活,一个变量既可以做整型,也可以是浮点型,也可以是字符串或者字符类型,通通只要在变量名前面加一个$然后加上你的变量 ...

  2. Objective-C 是如何慢慢走红的?

    对大多数人来说,Objective-C都是陌生的,原因在于它的走红过程太短.但透过Objective-C的火爆,我们就不难理解苹果程序商店的应用程序为什么轻易就突破了十万个. Objective-C的 ...

  3. Demo3

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  4. Kubernetes如何支持有状态服务的部署?

    作者:Jack47 转载请保留作者和原文出处 PS:如果喜欢我写的文章,欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. Kubernetes对无状态服务有完善的支持 ...

  5. python字符串27种常见的方法

    如有字符串 mystr = 'hello world itcast and itcastcpp' ,以下是常见的操作: <1>find 检测 str 是否包含在 mystr中,如果是返回开 ...

  6. 刚收到一个吃瓜群众看了肯定不信的offer!

    我教过了很多学生了,有的毕业后跟我依然保持联系,有的不知所踪,有的越混越好,有的没有什么变化,这让我不断思考,到底拉开人与人之间差距的是什么呢?

  7. 在Windows上安装Git

    实话实说,Windows是最烂的开发平台,如果不是开发Windows游戏或者在IE里调试页面,一般不推荐用Windows.不过,既然已经上了微软的贼船,也是有办法安装Git的. Windows下要使用 ...

  8. python redis模块的常见的几个类 Redis 、StricRedis和ConnectionPool

    日常写代码过程中,经常需要连接redis进行操作.下面我就介绍下python操作redis模块redis中的几个常见类,包括redis连接池. 一.StrictRedis 类 请看代码:. #!/us ...

  9. 关于Apple开发者的D-U-N-S Number

    企业开发者需要这个信息,中文译名叫邓白氏编码,很多攻略给的那个申请地址已经失效,这个组织官方也有地址可以提交申请资料,不过得注册,苹果目前可用的地址是:https://developer.apple. ...

  10. BigDecimal常用的加减乘除算法、比较大小、保存两位小数点

    项目中涉及到了BigDecimal的加.减.乘.比较大小.精确度的问题.所以在此总结一下,方便以后复习. //加法 BigDecimal coins = new BigDecimal("0& ...