栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

云学编程的第11天—【微软官方python入门教程 P23-P24笔记】2021-11-11 and和布尔标记

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

云学编程的第11天—【微软官方python入门教程 P23-P24笔记】2021-11-11 and和布尔标记

 P23 and和布尔标记

 

Sometimes you can combine conditions with AND instead of nesting if statements

[ requirements for honour roll

`Minimum 85% grade point average

`Lowest grade is at least 70% ]

if gpa >= .85: and lowest_grade >= .70:
    print('Well done')

How AND statements are processed

The way and statements are processed is both conditons must be true for the condition to be evaluated as true.

If you need to remember the results of a condition check later in your code, use Boolean variables as flags

if gpa >= .85 and lowest_grade >= .70:
    honour_roll = True
else:
    honour_roll = False
# Somewhere later in your code
if honour_roll:
    print('well done')

P24实操

`AND

# A student makes honour roll if their average is >= 85
# and their lowest grade is not below 70
gpa = float(input('What was your grade point Average?'))
lowest_grade = float(input('What was your lowest grade?'))

if gpa >= .85 and lowest_grade >= .70:
    print('You made the honour roll')

 

`True  False 或者 1 0

gpa = float(input('What was your grade point Average?'))
lowest_grade = float(input('What was your lowest grade?'))
if gpa >= .85 and lowest_grade >= .70:
    honour_roll = True
else:
    honour_roll = False
 #later in your code if you need to check 
if honour_roll:
    print('You made the honour roll')
if gpa >= .85 and lowest_grade >= .70:
    honour_roll = 1
else:
    honour_roll = 0

 

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/461713.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号