Python面试题(二)

打印九九乘法表

思路:利用字符串的连接,梯形输出结果

>>> def st(num):
... l = []
... for x in xrange(1, num + 1):
... str1 = ''
... for y in xrange(1, x + 1):
... str1 = str1 + '%d * %d = %s ' % (y, x, str(y*x))
... l.append(str1)
... for i in l:
... print i
...
>>>
>>>
>>> st(3)
1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9

generated by haroopad

上一篇:STM32之USART库函数USART_SendData的bug


下一篇:Swift URL Schemes使用