coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题

编写一个名为checkingIfIn的函数,接受三个参数。第一个参数为必需的字符串,第二个参数为可选布尔值,默认为True,第三个参数为可选字典,默认值为{'apple': 2, 'pear': 1, ...}。当第二个参数为True时,检查第一个参数是否为第三个参数的键,如果为键返回True,否则返回False。当第二个参数为False时,检查第一个参数是否不是第三个参数的键,如果不是则返回True,如果是则返回False。此外,编写一个test函数,根据布尔参数来检查整数是否为字典的键并返回对应值或False。" 136126178,7337247,Spark中的强化学习实践:Q-learning算法与大规模优化,"['大数据', '人工智能', '强化学习', 'Spark', '计算']
摘要由CSDN通过智能技术生成

Write a function called checkingIfIn that takes three parameters. The first is a required parameter, which should be a string. The second is an optional parameter called direction with a default value of True. The third is an optional parameter called d that has a default value of {‘apple’: 2, ‘pear’: 1, ‘fruit’: 19, ‘orange’: 5, ‘banana’: 3, ‘grapes’: 2, ‘watermelon’: 7}. Write the function checkingIfIn so that when the second parameter is True, it checks to see if the first parameter is a key in the third parameter; if it is, return True, otherwise return False.
But if the second paramter is False, then the function should check to see if the first parameter is not a key of the third. If it’s not, the function should return True in this case, and if it is, it should return False.

def checkingIfIn( x, direction = True , d = {
   'apple': 2, 'pear': 1, 'fruit': 19, 'orange': 5, 'banana': 3, 'grapes': 2, 'watermelon': 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值