zoukankan      html  css  js  c++  java
  • 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 #结束当前循环

     

  • 相关阅读:
    Python编程题32最小栈
    Python编程题31用列表实现队列
    Python编程题34用队列实现栈
    Python编程题40验证字母表的顺序
    Python编程题36三个数的最大乘积
    Python编程题39所有奇数长度子列表的和
    RTX 3090的深度学习环境配置指南:Pytorch、TensorFlow、Keras。配置显卡
    python numpy实现SVD 矩阵分解
    linux安装tomcat部署静态网页
    python使用deepwalk模型算节点相似度
  • 原文地址:https://www.cnblogs.com/Macal/p/6753038.html
Copyright © 2011-2022 走看看