2021年2月3日星期三

Is there a more efficient way to write this multiplication table?

I´m trying to make a multiplication table like this one

2 X 1 = 2          3 X 1 = 3           4 X 1 = 4           5 X 1 = 5             2 X 2 = 4          3 X 2 = 6           4 X 2 = 8           5 X 2 = 10            2 X 3 = 6          3 X 3 = 9           4 X 3 = 12          5 X 3 = 15            2 X 4 = 8          3 X 4 = 12          4 X 4 = 16          5 X 4 = 20     

Is there a more efficient and cleaner way to do this, this is my code.

#By 1  for a in range(2, 6):     print(f"{a} X {1} = {a*1}", end="          ")  print("")    #By 2  for b in range(2, 6):     print(f"{b} X {2} = {b*2}", end="          ")  print("")    #By 3  for c in range(2, 6):     print(f"{c} X {3} = {c*3}", end="          ")  print("")    #By 4  for d in range(2, 6):     print(f"{d} X {4} = {d*4}", end="          ")  print("")  

I´m learning how to code in python.

https://stackoverflow.com/questions/66037926/is-there-a-more-efficient-way-to-write-this-multiplication-table February 04, 2021 at 08:57AM

没有评论:

发表评论