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)]
  • 相关阅读:
    软件设计文档
    java基础路线与详细知识点
    hdu 2203 亲和串 kmp
    UVALive 6915 J
    UVALive 6911 F
    UVALive 6906 A
    hdu 3746 Cyclic Nacklace KMP
    hdu 1686 Oulipo kmp算法
    hdu1711 Number Sequence kmp应用
    hdu4749 kmp应用
  • 原文地址:https://www.cnblogs.com/bcaixl/p/11504825.html
Copyright © 2011-2022 走看看