python全栈day2

day02 基础&运算符

今日概要

    1. 循环
    2. 字符串的格式化
    3.  运算符
    4.  编码
    5.  博客&git

肉容回顾&补充

内容回顾

  • 计算机基础

  • 安装解释器

    • py2
    • py3
  • 语法

    • print/input
    • 整型 int/字符串 str / 布尔值 boolen
    • 条件语句
    • and 运算符
    • 变量
  • 练习:

    # -*- coding:utf-8 -*-
    
    """
    评分规则:
    A >= 90
    B >= 80
    C >= 70
    D >= 其他
    用户输入成绩,根据成绩的不同显示不同的级别。
    """
    
    
    score = input("请输入你的成绩:")
    score_int = int(score)
    if score_int >= 90:
        print("A")
    elif score_int >= 80:
        print("B")
    elif score_int >= 70:
        print("C")
    else:
        print("其他")
    

    问题

    • if缩进
    • coding 单词书写错误,写成conding
    • 字符串没有转为整数类型就时行比较,数字比较一律转换成数字类型
    • score 分值

补充

  1. if条件的嵌套

    # -*- coding:utf-8 -*-
    
    message = """欢迎致电10086
    1.话费查询;
    2.流量服务;
    3.业务办理;
    4.人工服务"""
    
    print(message)
    
    index = input("请输入你要选择的服务:")
    index = int(index)
    
    if index == 1:
        print("话费查询")
    
    elif index == 2:
        print("流量服务")
    
    elif index == 3:
        content = """业务办理
        1.修改密码;
        2.更改套餐;
        3.停机;"""
        print(content)
        value = input("请输入要办理的业务:")
        value = int(value)
        if value == 1:
            print("修改密码")
        elif value == 2:
            print("更改套餐")
        elif value == 3:
            print("停机")
        else:
            print("输入错误")
    
    elif index == 4:
        print("人工服务")
    
    else:
        print("输入错误")
    
  2. pycharm可以变更解释器

    1576763935380

今日内容

## 1. 循环语句

1. while 结构

count = 1
while count <= 10:

    print(count)

    count += 1

2. break

 while True:
     print ("你好")
     while True:
         print(666)
         break

3. continue

count = 1
while count <= 10:

    if count == 7:
        count += 1
        continue # 遇到continue,不在继续往下起,而是回到while判断
    print(count)

    count += 1

4. while else

"""
count = 1
while count < 10:
    print(count)
    count += 1
else:  # 不在满足while后的条件时,触发。 或 条件=False
    print("else代码块")
print("结束")
"""

count = 1
while True:
    print(count)
    if count == 10:
        break
    count += 1
else:  # 不在满足while后的条件时,触发。 或 条件=False
    print("else代码块")
print("结束")

5. 其他

  • 快速注释 ctrl + /
  • pycharm断点

6. 总结

  • while基本结构
  • break
  • continue
  • while else

2. 字符串格式化

1. %s
    2. %d
    3. %%
    4. 注意:在    "我叫%s" % ("ly",)      # 括号里边元组的元数后要加“   ,   ” 号

3. 运算符

4.编码

  • 编码扩展

    • ascii
    • unicode
      • ecs2
      • ecs4
    • utf-8,中文用3字节
    • utf-16
    • gbk,中文用2字节
    • gb2312,中文用2字节
  • 单位

    8bit = 1byte

    1kB = 1024byte

    1MB =1024KB

    1GB = 1024MB

    1TB = 1024GB

    后边还有:TB,PB ,EB,ZB,YB,BB,NB,DB ……

5. 博客

博客园开自己的博客

  • 注册
  • 申请开通博客
  • 写博客
    • 随笔,随便看。
    • 文章,有URL就能看。
    • 日志,只能自己看。
    • 皮肤

6. git

  • 安装git软件(下一步直到完成)

  • 码云注册(保存代码)

  • 创建代码托管的舱库

  • 写作业并提交到码云。

    • 在某个文件夹下写作业

    • 写完之后,在此文件夹下 鼠标右键,并选择 [git bash here]

    • 在黑框里输入命令

      • git全局设置

        第一次执行此命令时候,需要行执行:
        git config --global user.name "洋之悟"
        git config --global user.email "[email protected]"
      • git init 用于做初始化,其实就是让git把当前所在的文件夹管理 起来。 每次都要做

      • git add . 将当前所在的文件夹中的所有文件收集起来。

      • git commit -m "第二天的作业" ,做个记录

        git remote add pyqzs21 https://gitee.com/yzwone/oldboy_pyqz_s21.git
      • git push pyqzs21 master

      • 提示:输入用户名和密码(码云)

猜你喜欢

转载自www.cnblogs.com/yzwone/p/12161687.html