if_else_while_for
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的更多相关文章
随机推荐
- 面试之路(27)-链表中倒数第K个结点
代码的鲁棒性: 所谓的鲁棒性是指能够判断输入是否合乎规范,能对不和规范的程序进行处理. 容错性是鲁棒性的一个重要体现. 防御性编程有助于提高鲁棒性. 切入正题,我可不是标题党: 链表倒数第k个节点 列 ...
- css3-------:before和:after的作用
1.:before和:after的作用就是在指定的元素内容(而不是元素本身)之前或者之后插入一个包含content属性指定内容的行内元素,最基本的用法如下: <!doctype html> ...
- 查询linux机器的公网ip
在linux终端提示符下,输入以下命令: curl members.3322.org/dyndns/getip 可以看到下图已经查询到公网IP地址了,就是这么简单
- JDK内置工具之一——JMap(java memory map)
1.介绍 打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量). 可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.使用方法 j ...
- jquery 设置占位符
<script type="text/javascript"> $(document).ready(function(){ $('.inputfiel ...
- 保证你能看懂的KMP字符串匹配算法
文章转载自一位大牛: 阮一峰原网址http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm ...
- mysql-列属性
列属性 列属性是真正约束字段的数据类型,但是数据类型的约束很单一,需要有一些额外的约束来确保数据的合法性 NULL/NOT NULL.default.primary key.unique key.au ...
- 部署网站: 配置项目到iis上运行报目录错误
配置项目到iis上运行报目录错误 以下三种方法可使用: 1.添加文件访问权限 everyone (线上环境慎用) 2.重新注册iis 3.web.config 加一段话 在<system.we ...
- flex调用JS报安全沙箱错误解决办法
flex调用JS方法弹窗时一般会报安全沙箱错误,只要将被调用的JS方法设置延时就可解决. function openKqQuery(){ window.showModalDialog("pa ...
- node传统读取文件和promise,async await,
先上传统文件加载方式代码,传统方式在处理多层嵌套时代码比较混乱 const fs = require('fs') //引入文件系统 function readFile (cb) { fs.readFi ...