【问题标题】:What call to the function will result in the following output?对函数的什么调用将导致以下输出?
【发布时间】:2020-06-04 04:15:43
【问题描述】:
def doh(a, b, c):
    if a[str(b)] + c == a[c + 'x']:
        print(b + 2)

期望输出:

11

我从哪里开始接近?这些变量的类型是什么?

【问题讨论】:

  • 你知道b + 2 必须是 11,所以 1 是 9。
  • 是的,那我该如何对待a和c来满足if语句呢?

标签: python dictionary set output


【解决方案1】:

解决方案

为变量 a,b,c 传递这些值

变量a必须是字典,变量b应该是整数9,变量c应该是字符串或字母

#function defenition
def doh(a, b, c):
    if a[str(b)] + c == a[c + 'x']:
        print(b + 2)

a = {'9':'d','cx':'dc'}
b=9
c='c'
doh(a, b, c)

结果

11

另一种解决方案

a = {'9':'michael','hix':'michaelhi'}
b=9
c='hi'
doh(a, b, c)

所以关系应该如下图所示。

我希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-04
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多