还有其他方法可以为乘法表编写循环以获取运行时值吗?
Any other way to write a loop for multiplication table to take run time values?
要打印乘法表,我使用的是 for 循环,它最多只有第 10 次表具有固定值。我需要乘法表作为运行时值。是否有替代循环在运行时获取值?这是我尝试过的代码:
scanf(&num);
for(i=num;i<=num;i++)
for (j=1;j<=10;j++)
这不是一个Python For loop
。在python中,你可以使用范围函数来拥有一个漂亮的乘法表。
def table_choice(my_choice=None):
for a in range(10):
if my_choice != None:
print('{0} x {1} = {2}'.format(my_choice, a, my_choice * a))
else:
for b in range(10):
print('{0} x {1} = {2}'.format(a, b, a * b))
table_choice(my_choice = 7)
输出:
7 x 0 = 0
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
如果你执行table_choice((,你将得到完整的表
请参阅:https://docs.python.org/3/library/functions.html#func-range 中的范围文档
相关文章:
- 为什么我的for循环不能正确获取argv
- 对于set上的循环-获取next元素迭代器
- 如何获取矢量循环的整数位置
- 与多个 for 循环与单个 for 循环 wrt 相关的性能从多映射获取数据
- 循环通过网格获取温度,但不知道如何告诉程序停止循环
- 如何在 for 循环中的特定时间内获取要打印的额外值
- 特征获取索引数组,其中向量中的值为真(不需要循环)
- 还有其他方法可以为乘法表编写循环以获取运行时值吗?
- 从循环中获取总价值
- 练习循环和使用循环 1 次以及如何获取数组的最大值
- 如何在每次迭代后在循环中获取变量的值?
- C++是否在 for 循环之前获取参数
- C++线程获取每个循环的值
- 具有获取函数的无限循环
- 如何循环访问在 cmd 中获取参数的 exe 文件
- 循环以使用 cstring 数组 c++ 获取用户输入
- C 编程:在循环时运行 2 并从 loop1 获取数据的随机结果
- 如何从文件中获取循环中的多行
- 在<Object>基于范围的 for 循环中从 std::vector 获取指向对象的指针
- C++循环中的获取线