码迷,mamicode.com
首页 > 其他好文 > 详细

pyhton随笔02

时间:2017-04-23 18:05:10      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:print   结束   odi   ...   ack   conf   输入密码   imp   confirm   

一、如何实现输入密码时不可见?

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

标签:print   结束   odi   ...   ack   conf   输入密码   imp   confirm   

原文地址:http://www.cnblogs.com/Macal/p/6753038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!