zoukankan      html  css  js  c++  java
  • python课堂整理1

     

    1.变量

    变量只能由字母、数字、下划线组成

    特例:1.变量不能用数字开头

         2.不能是python的关键字

              3.最好不要和python内置的东西重复

    让变量名有意义 些

    python3的关键字如下:

    False, None, True, and, as, assert, break, class, continue, def, del, elif, else, except, finally, for, from, global, if, import, in, is
    lambda, nonlocal, not, or, pass, raise, return, try, while, with, yield

    2.循环的例题

    1.使用循环语句输出123456  89 10

    n = 1
    while n <=10:
        if n == 7:
            pass
        else:
            print(n)
        n = n + 1
    

    2.求1 - 100 的所有数的和

    n = 1
    count = 0
    while n <= 100:
        count = count + n 
        n = n +1
    print(count)
    

    3.输出1 - 100 内的所有奇数

    n = 1
    while n <= 100:
      if n % 2 != 0:
        print(n)
      n = n + 1

     4.输出1 - 100 内的所有偶数

    n = 1
    while n <= 100:
        if n % 2 == 0:
            print(n)
        n = n + 1
    

    5.求1-2+3-4...+99的所有数的和

    n = 1
    count = 0
    while n <= 5:
        if n % 2 == 0:
            count = count - n
        else:
            count = count + n
        n = n + 1
    print(count)

    6.用户登录,三次机会重试

     下面代码是自己写的,还未听老师的修改

    n = 3
    id1 = "大白"
    passwd = "521"
    while n >= 1:
        user = input("请输入用户名:")
        userid = input("请输入密码:")
            
        if user == id1 and userid == passwd :
            print("登录成功")
        else:
            print("用户名或密码错误,请重新输入!")
        n = n - 1
    print("机会用完了qaq")
     
    一个奋斗中的产品小白
  • 相关阅读:
    dijkstra算法模板 -- 最短路
    0-1背包
    POJ 1456-Supermarket(贪心+并查集)
    CodeForces 556C
    CodeForces
    POJ 2253-Frogger(Floyd变形)
    POJ 1251-Jungle Roads(最小生成树)
    HDU 1846-Brave Game(巴什博弈)
    HDU 1233-还是畅通工程(经典最小生成树)
    51Nod 1649-齐头并进(最短路dijkstra)
  • 原文地址:https://www.cnblogs.com/dabai123/p/10920261.html
Copyright © 2011-2022 走看看