pyhton随笔02
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pyhton随笔02相关的知识,希望对你有一定的参考价值。
一、如何实现输入密码时不可见?
import getpass
pwd= getpass.getpass(“请输入密码:")
(pycharm内可能不可用)
二、if.....else
age=25
guess_age = int(input(‘你猜我多少岁?‘)) #python3.X 中input的是一个str,需要int()
if guess_age == age:
print(‘Yes,you got it!‘)
elif guess_age > age:
print(‘think smaller‘)
else :
print(‘think bigger‘)
三、while
count = 0
while True:
print(‘count:’,count)
count = count +1
#guess age
age=25
count = 0
while count < 3:
guess_age = int(input(‘你猜我多少岁?‘))
if guess_age == age:
print(‘Yes,you got it!‘)
elif guess_age > age:
print(‘think smaller‘)
else :
print(‘think bigger‘)
count +=1
if count ==3:
continue_confirm = input(‘Do you want to continue?‘:)
if continue_confirm != "n":
count = 0
#else:
# print(‘you have try too many times‘)
三、for循环
for i range(10):
print(”loop:“,i)
for i range(0,10,3):#从0开始,到10结束,步长为3
print(”loop:“,i)
#guess age
age=25
count = 0
for i in range(3):
guess_age = int(input(‘你猜我多少岁?‘))
if guess_age == age:
print(‘Yes,you got it!‘)
elif guess_age > age:
print(‘think smaller‘)
else :
print(‘think bigger‘)
count +=1
else:
print(‘you have try too many times‘)
#! usr/bin/env python
# encoding:utf-8
# __author__="Macal"
‘‘‘
for i in range(0,10):
if i < 5:
print("loop",i)
else:
continue
print(‘hehe‘)
‘‘‘
for i in range(10):
print(‘----------‘, i)
for j in range(10):
print(j)
if j > 5:
break #结束当前循环
以上是关于pyhton随笔02的主要内容,如果未能解决你的问题,请参考以下文章
pyhton—opencv直线检测(HoughLines)找到最长的一条线