CS 61A 2020 fall Disc 01: Environment Diagrams, Control

这篇博客介绍了CS 61A课程中的环境图概念,探讨了如何根据温度和降雨情况判断Alfonso是否穿夹克,并通过编程实现。此外,文章还讲解了如何确定一个正整数是否为质数,以及运用环境图来表示变量的赋值过程。最后,提供了代码执行后的环境图绘制教程。
摘要由CSDN通过智能技术生成

1.1 Alfonso will only wear a jacket outside if it is below 60 degrees or it is raining.

Write a function that takes in the current temperature and a boolean value telling
if it is raining and returns True if Alfonso will wear a jacket and False otherwise.
First, try solving this problem using an if statement.

def wears_jacket_with_if(temp, raining):
"""
>>> wears_jacket_with_if(90, False)
False
>>> wears_jacket_with_if(40, False)
True
>>> wears_jacket_with_if(100, True)
True
"""

def wears_jacket_with_if(temp, raining):
    if temp < 60 or raining:
        return True
    else:
        return False

Note that we’ll either return True or False based on a single condition, whose
truthiness value will also be either True or False. Knowing this, try to write this
function using a single

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值