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

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

云学编程的第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

 

 

 

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5437215.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存