zoukankan      html  css  js  c++  java
  • 【Kata Daily 190911】Multiplication Tables(乘法表)

    题目:

    Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings.

    Example:

    multiplication_table(3,3)

    1 2 3
    2 4 6
    3 6 9

    -->[[1,2,3],[2,4,6],[3,6,9]]

    Each value on the table should be equal to the value of multiplying the number in its first row times the number in its first column.

    解题办法:

    def multiplication_table(row, col):
        L = []
        # Good Luck!
        for i in range(1, row+1):
            L1 = []
            for j in range(1, col+1):
               mul = i * j
               L1.append(mul)
            L.append(L1)
        return L

    这题还是挺简单的。按照思路来就好

    看一下网友的简写一句话的写法:

    def multiplication_table(row,col):
        return [[(i+1)*(j+1) for j in range(col)] for i in range(row)]
  • 相关阅读:
    Qt之QFileSystemWatcher
    Qt之qSetMessagePattern
    物联网操作系统HelloX V1.80测试版发布
    CoreOS Linux available in China
    等火车
    HTTP 简介
    建造模式Builder
    MariaDB exists 学习
    javascript 中 typeof 的使用
    Java字符串null相加
  • 原文地址:https://www.cnblogs.com/bcaixl/p/11504825.html
Copyright © 2011-2022 走看看