问题:Write a function called twenty(a,b) which takes as parameters two numbers a and b. if either of a or b = 20, or a + b = 20, or a – b = 20, or a * b = 20 or a/b = 20 then the function should return True. Otherwise the function should return False.
翻译:编写一个名为 twenty(a,b) 的函数,该函数将两个数字 a 和 b 作为参数。如果 a,b 为 20,或符合 a + b = 20,a – b = 20,a x b = 20,a / b = 20,则该函数应输出True。否则,该函数应输出False。
Python代码如下:
def twenty(a,b):
a = int(input("Please Enter a "))
b = int(input("Please Enter b "))
if a == 20 or b == 20 or a+b == 20 or a-b == 20 or a*b == 20 or a/b == 20:
print("True")
else:
print("False")
twenty(any,any)
输出结果如下:
Please Enter a 5 Please Enter b 15 True Please Enter a 20 Please Enter b 7 True Please Enter a 3 Please Enter b 9 False
感谢阅读,欢迎指教



