【问题标题】:Function that will receive 2 numbers as input and it should return the multiplication of these 2 numbers将接收 2 个数字作为输入的函数,它应该返回这 2 个数字的乘积
【发布时间】:2018-11-20 16:12:22
【问题描述】:

我正在玩 Checkio 网站以了解有关 python 的更多信息,但我似乎无法解决第一个问题。就是这样:

编写一个接收 2 个数字作为输入的函数,它应该返回这 2 个数字的乘积。

输入:两个参数。两者都是int

输出: Int.

现在,他们给了我这个代码:

def mult_two(a, b):
  # your code here
  return mult_two


if __name__ == '__main__':
    print("Example:")
    print(mult_two(3, 2))

    # These "asserts" are used for self-checking and not for an auto-testing
    assert mult_two(3, 2) == 6
    assert mult_two(1, 0) == 0
    print("Coding complete? Click 'Check' to earn cool rewards!")

在#Your code here 部分,我需要添加答案,但我不知道。请帮忙。

【问题讨论】:

  • 作为一个起点,想想你将如何编写一个将两个数字相乘的程序,没有一个函数。然后获取该代码并将其放入您的函数中。
  • 我试着把这个:def mult_two(a, b): mult_two= 3*2 return mult_two
  • 尝试编辑问题。不要放在 cmets 中
  • 但它给了我这个错误:示例:6 AssertionError: , 12
  • 提示:一般来说,函数的参数应该在函数体内使用。换句话说,ab 应该出现在您的 return 语句中。

标签: python input int multiplication


【解决方案1】:

您的问题似乎很基本。以下是编写函数 mult_two 的一种可能方式:

def mult_two(a, b):
   """ Return the product of the two arguments."""
    return a * b

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多