• 1,python初识


    什么是变量?

    变量:将程序的中间结果暂时存储起来,以便后续程序调用。

    什么是字符串类型?

    python中被引号引起来的数据就是字符串。字符串类型,也简称str类型。

    在python中 int是什么?

    ‘int’在python中代表的是数字类型,用于算数计算。

    python的分类

    编译型

    将代码一次性全部编译成二进制,然后再运行。

    优点:执行效率高

    缺点:发开效率低,不能跨平台

    代表语言 C

    解释性

    代码逐行解释,解释成二进制,然后运行。

    优点:开发效率高,能引用第三方库,可以跨平台。

    代表语言 python

    变量规则

    1,必须是字母,数字,下划线,任意组合。

    2,不能是数字开头。

    3,不能是python中的关键字。

    4,要具有可描述性

    5,变量名不能太长。

    6,变量不能是中文。

    常量

    一直不变的量,默认全部大写的变量为常量。

    基础数据类型

    int:数字,整数,用于计算。

    str:字符串,在python中,凡是用引号引起来的全都是字符串。(不管单引号还是双引号)

    bool : True False 两种状态,判定代码的真假。

    while循环

    如何终止循环

    1,改变条件

    2,break(直接结束循环)

    continue

    结束本次循环,继续下一次循环。

     五种if语句

    第一种结构:
    if 条件:
        结果
    第二种结构:
    
    if 条件:
        结果
    else:
        结果
    第三种结构:
    choice = input('请输入你的猜的数字:')
    if choice == '2':
        print('我请你吃饭')
    elif choice == '6':
        print('免一周作业')
    elif choice == '3':
        print('一起去大保健')
    第四种结构:
    choice = input('请输入你的猜的数字:')
    if choice == '2':
        print('我请你吃饭')
    elif choice == '6':
        print('免一周作业')
    elif choice == '3':
        print('一起去大保健')
    else:
        print('选择错误.....')
    第五种结构:
    if 条件:
        if 条件:
            结果
        else:
            结果
    else:
        结果

    1、使用while循环输入 1 2 3 4 5 6     8 9 10

    count = 0
    while count <= 9:
        count += 1
        if count == 7:continue
        print(count)

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

    count = 1
    sum = 0
    while True:
        sum = count + sum
        count += 1
        if count == 101:break
    print(sum)

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

    count = 1
    while count <= 100:
        count += 2
        print(count)

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

    count = 1
    while count <= 100:
        count += 2
        print(count-1)

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

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

    6、用户登陆(三次机会重试)

    i = 0
    name = 'zhangyajie'
    pwd = '123'
    while i < 3:
        ccc = input('请输入用户名:')
        ppp = input('请输入密码:')
        if ccc == name and pwd == pwd:
            print('登陆成功')
            break
        else:
            print('登陆失败请重新登陆')
            i += 1
  • 相关阅读:
    PHP 实现定时任务的几种方法
    ueditor 文本编辑器
    CodeIgniter 如何去掉 Index.php
    php 后台权限例子 (mysql 数据表)
    php ajax 下拉加载数据
    Codeforces 931.D Peculiar apple-tree
    Codeforces 931.C Laboratory Work
    Codeforces 932.F Escape Through Leaf
    bzoj2325 [ZJOI2011]道馆之战
    bzoj3611 [Heoi2014]大工程
  • 原文地址:https://www.cnblogs.com/ZJGG/p/8954008.html
Copyright © 2020-2023  润新知