• 大三上周总结


    所学时间(包括上课) 二十二个小时以上
    代码量(行) 1k左右
    博客量 2篇
    了解到的知识点 python逻辑运算
    编译原理
    设计模式
    算法与数据结构

    逻辑运算

    python中的逻辑运算符包括:与and/或or/非not三种

    and

    条件1 and 条件2 只要有一个条件不成立,就返回false

    or

    条件1 or 条件2 条件1成立或者条件2成立

    not

    not 非 取反

    示例:

    age = int(input())
    if 0 <= age <= 120:
        print("Yes")
    else:
        print("No")
    python_score = int(input())
    c_score = int(input())
    if python_score >= 60 or c_score >= 60:
        print("考试通过")
    else:
        print("不通过")
    is_employ = bool(input())
    if not is_employ:
        print("非本公司人员请勿入内")
    else:
        print("欢迎")
    

    在开发中使用elif来增加一些条件,条件不同,需要执行的代码也不同

    holiday_name = input()
    if holiday_name == "情人节":
        print("买玫瑰,看电影")
    elif holiday_name == "平安夜":
        print("买苹果,吃大餐")
    elif holiday_name == "生日":
        print("买蛋糕")
    else:
        print("每天都是节日啊")
    

    if的嵌套注意语法格式

    整体向右增加缩进按下 tab整体减少缩进按下shift+tab

    has_ticket = bool(input())
    knife_length = int(input())
    
    if has_ticket:
        print("车票检查通过,准备开始安检")
        if knife_length > 20:
            print("刀的长度为%d,不允许上车" % knife_length)
        else:
            print("安检通过")
    else:
        print("请先买票")
    

    示例:石头剪刀布

    import random
    player = int(input("请输入您要出的拳 石头(1)/剪刀(2)/布(3):"))
    
    computer = random.randint(1, 3)
    print("玩家选择的拳头是 %d - 电脑出的拳是 %d" % (player, computer))
    if ((player == 1 and computer == 2)
            or (player == 2 and computer == 3)
            or (player == 3 and computer == 1)):
        print("玩家胜")
    elif player == computer:
        print("平局,再来一盘")
    else:
        print("电脑胜")
    

    random.randint(a,b),返回[a,b]之间的随机数,闭区间,包含ab

  • 相关阅读:
    扁鹊见蔡桓公
    月出
    TypeScript 基本类型
    随机漂浮图片广告实例代码
    js实现的随机颜色实例代码
    初识JavaScript 变量, 操作符, 数组
    HTML5的新结构标签
    14款超时尚的HTML5时钟动画
    CSS如何设置div半透明效果
    Google Doodle 2015圣诞版背后的故事与十年圣诞回顾
  • 原文地址:https://www.cnblogs.com/125418a/p/14211949.html
Copyright © 2020-2023  润新知