import os
import sys
def main():
#For loop to show 9 X 9 matrix
for i in range(1, 10, 1):
for j in range(1, 10, 1):
print(i * j, end=" ")
print()
if __name__ == '__main__':
main()
class multiplication():
def table():
#For loop to show 9 X 9 matrix
for i in range(1, 10, 1):
for j in range(1, 10, 1):
print(i * j, end=" ")
print()
if __name__ == '__main__':
a = multiplication
a.table()
Use list to rewrite
class multiplication():
def table():
num1 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
num2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
#For loop to show 9 X 9 matrix
for i in range(0, 9, 1):
for j in range(0, 9, 1):
print(num1[i] * num2[j], end=" ")
print()
if __name__ == '__main__':
a = multiplication
a.table()
Ref:
0 意見:
張貼留言