zoukankan      html  css  js  c++  java
  • Python 学习第一周

    一、pycharm安装

    https://www.cnblogs.com/dcpeng/p/9031405.html

    二,代码联系

    1、输入输出(明文):

      username = input("usrname:")

           password = input("password:")

      print(username,password)

    2、输入输出(暗文):

    import getpass ##输入的时候没有显示输入字符

     username = input("usrname:")

    password = getpass.getpass("password:")
    print(username,password)

    3、验证输入的账号密码是否正确:

    _username = 'alex'
    _password = 'abc123'
    username = input("username")
    password = input('password:')
    if _username == username and _password ==password:
    print("Welcome user {name} login...".format(name=username))
    else:
    print("Invalid username or password!")

     4、猜年龄 if else 

    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!")

    5、while循环
    count = 0
    while True:
    print("count:",count)
    count = count+1
    if count ==100:
    break
    输出0-99
    
    
    count = 0
    while True:
    if count ==3:
    break
    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+=1
    6、优化后
    age_of_oldboy = 56
    count = 0
    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+=1
    7、for 循环
    for i in range(10):
    print("loop",i)

    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 ..")

    8、有间隔的for循环
    for i in range(0,10,3):##隔三个数
    print("loop",i)

    输出结果

    loop 0
    loop 3
    loop 6
    loop 9

    9、用户控制

    age_of_oldboy = 56
    count = 0
    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+=1

    if count==3:####重点
    continue_confirm = input("do you want to keep guessing?")
    if continue_confirm !='n':
    count =0
    10、双层循环

    for i in range(10):
    print('--------',i)
    for j in range(10):
    print(j)
    if j>5:
    break
  • 相关阅读:
    leetcode 576. Out of Boundary Paths 、688. Knight Probability in Chessboard
    leetcode 129. Sum Root to Leaf Numbers
    leetcode 542. 01 Matrix 、663. Walls and Gates(lintcode) 、773. Sliding Puzzle 、803. Shortest Distance from All Buildings
    leetcode 402. Remove K Digits 、321. Create Maximum Number
    leetcode 139. Word Break 、140. Word Break II
    leetcode 329. Longest Increasing Path in a Matrix
    leetcode 334. Increasing Triplet Subsequence
    leetcode 403. Frog Jump
    android中webView加载H5,JS不能调用问题的解决
    通过nginx中转获取不到IP的问题解决
  • 原文地址:https://www.cnblogs.com/hapen66/p/10963023.html
Copyright © 2011-2022 走看看