Fill in the box with python code that will make the program behavior match the comments. You may not make any other changes to the code or add code outside the parenthesis " ( )" .
def bypass_line(age, has_acces_card): ''' (int, bool) -> bool Return True if and only if the person's age is greater than 50 or they have a access card as indicated by has_access_card. ''' return ( )
这是我正在做的练习题。我进退两难,我知道怎么写代码。。。你知道吗
即:
def bypass_line(age, has_vip):
if age >70 or has_vip =="yes":
return True
return False
但是如何在()中编写一行代码以便回答问题呢?你知道吗
在您的旁路线函数,您可以简单地写
因为我更喜欢C++,所以我喜欢组织这样的代码。它帮助我想得更清楚。你知道吗不管是哪种方式,代码只是检查
如果其中一个为真(因此
or
),函数将返回True
。否则,它将返回一个false。你知道吗逻辑与
if
语句中的逻辑完全相同,只是结果True
或False
被用在return
语句中(仍然有相同的表达式,只是结果被用在其他地方)。您可以在任何地方使用该表达式(或任何表达式),例如在print
中,变量的定义,作为函数的参数。。。逻辑总是一样的。你知道吗像这样:
这基本上是返回由if语句计算的表达式本身。因为表达式已经在if语句中返回
True
或False
,所以它在这里也会这样做。你知道吗您的
if
表达式已生成一个布尔值;它是True
或False
。您可以直接退回:这基本上就是
if
测试的内容;获取表达式,将其传递给bool()
,然后查看它是True
还是False
。这里不需要bool()
,因为比较运算符(>
和==
)本身已经返回True
或False
:相关问题 更多 >
编程相关推荐