zoukankan      html  css  js  c++  java
  • python day04

    一.常量

     在python中没有一个专门的语法代表常量 程序员约定俗称用变量名的全部大写代表常量

    二.基本运算符补充

     1.算术运算

       print(10 / 3)

       print(10 // 3

      2.赋值运算之增量赋值

     例  age=18

           age=age+1

           age += 1

       3.赋值预算之交叉赋值

      例 x=10 y=20

          temp=x

          y=x

          temp=y

          x,y=y,x

        4. 链式赋值      

            x=10

            y=x

            z=y
            x=y=z=10
            print(id(x))
            print(id(y))
            print(id(z))

         5. 解压赋值

        例:L[1.2,2.2,3.3,4.4,5.5]

             a,b,c,d,e,=L

             print(a,b,c,d,e)

    三.if 判断

         语法1

    age_of_bk=30
     print('start...')
    
     inp_age=input('>>>:')
     inp_age=int(inp_age)
     if inp_age == age_of_bk:
         print('猜对了')
    语法2
    age=19
     gender='female'
     is_beautifui=True
    
     if age >= 18 and age <= 25 and gender == 'female' and is_beautifui:
         print('开始表白...')
    
     else:
         print('阿姨好')
    语法3
     score=input('youe csore')
     score=int(score)
     if score >= 90:
         print('优秀')
     elif score >= 80:
         print('良好')
     elif score >= 70:
        print('普通')
     else:
         print('垃圾')
    

      语法4

     age=50
     gender='famale'
     is_beautiful=True
     is_successful=True
     if age >=18 and age <= 25 and gender == 'famale' and is_beautiful:
         print('表白.....')
     else:
         print('我逗你玩呢')
    

      

      

      

    四.while循环: 条件循环

     while之"条件循环"
     name_of_bk='egon'
     pwd_of_bk='123'
     tag=True
     while tag:
         inp_name=input('your name>>:')
         inp_pwd=input('your password>>:')
         if inp_name == name_of_bk and inp_pwd == pwd_of_bk:
             print('login successful')
             tag=False
         else:
             print('username or password error')
             print('other code...')
     while+break break代表结束本层循环
     while True:
         print(1)
         break
         print(2)
         print(3)
     name_of_bk='egon'
     pwd_of_bk='123'
     while True:
         inp_name=input('your name>>:')
         inp_pwd=input('your password>>:')
         if inp_name == name_of_bk and inp_pwd == pwd_of_bk:
             print('login successful')
             break
         else:
             print('urername or password error')
             print('other code...')
     while+continue continue代表结束本次循环直接进入下一次 count=1 while count<6:     if count==3:         count+=1         continue     print(count)     count+=1 name_of_bk='egon' pwd_of_bk='123' count=0
     while True:
         if count == 3:
    
             print('输错的次数过多...')
             break
         inp_name=input('your name>>:')
         inp_pwd=input('your password>>:')
         if inp_name == name_of_bk and inp_pwd == pwd_of_bk:
             print('login successful')
             break
         else:
             print('username or password error')
             count += 1
    
     while+else else('else的子代码块只有在while循环没有被break打断的情况下才会执行')
     count = 0
     while True:
         if count == 10:
             break
         print(count)
         count += 1
     while+else else('else的子代码块只有在while循环没有被break打断的情况下才会执行')
     count = 0
     while True:
         if count == 10:
             break
         print(count)
         count += 1
    
     count=0
     while count <= 10:
         print(count)
         count += 1
    
    
     name_of_bk='egon'
     pwd_of_bk='123'
    
     count = 0
     tag = True
     while tag:
         if count == 3:
             print('输错的次数过多')
             break
         inp_name=input('your name>>:')
         inp_pwd=input('your password')
         if inp_name == name_of_bk and inp_pwd == pwd_of_bk:
             print('iogin successful')
             while tag:
                 print("""
                 0 退出
                 1 购物
                 2 支付
                 3 查看购物
                 """)
                 cmd = input('>>>:')
                 if cmd == '0':
                     tag = False
                     continue
                 elif cmd == '1':
                     print('购物...')
                 elif cmd == '2':
                     print('支付.....')
                 elif cmd == '3':
                     print('查看购物车')
                 else:
                     print('输入错误的指令')
         else:
             print('username or password error')
             count += 1


  • 相关阅读:
    Mvvm combobox绑定Dictionary问题
    类型转化方法(处理System.Nullable类型)
    linq 动态查询
    VS 2005 / 2008 / 2010 能否继续使用 ASP.NET 1.x版的DataGrid ????
    使用 Using...End Using区块来写程序,要非常小心!
    [习题]TreeView、Menu、SiteMapPath #2 多国语系 /当地语系 / Localization
    Repeater,不用自己写循环 (Loop)
    [习题]给初学者的范例,多重字段搜寻引擎 for GridView,兼论 SqlDataSource与SelectParameter的用法
    ASP.NET案例精编(清华大学出版社 / 作者MIS2000Lab)「勘误表」、补充习题与档案下载
    Windows Vista / 7减少不必要的服务、最佳化(优化)
  • 原文地址:https://www.cnblogs.com/zhouyuquan/p/9991016.html
Copyright © 2011-2022 走看看