multiplication_table 函数打印传递给它的数字乘以 1 到 5 的结果。一个额外的要求是结果不超过 25,这是通过 break 语句完成的。填空完成函数满足这些条件
def multiplication_table(number):
# Initialize the starting point of the multiplication table
multiplier = 1
# Only want to loop through 5
while multiplier <= 5:
result = 1
# What is the additional condition to exit out of the loop?
if ___ :
break
print(str(number) + "x" + str(multiplier) + "=" + str(result))
# Increment the variable for the loop
___ += 1
multiplication_table(3)
# Should print: 3x1=3 3x2=6 3x3=9 3x4=12 3x5=15
multiplication_table(5)
# Should print: 5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
multiplication_table(8)
# Should print: 8x1=8 8x2=16 8x3=24
原文由 Frank 发布,翻译遵循 CC BY-SA 4.0 许可协议
if result > 25:
和
multiplier += 1