【发布时间】: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 -
提示:一般来说,函数的参数应该在函数体内使用。换句话说,
a和b应该出现在您的 return 语句中。
标签: python input int multiplication