dfkt.net
当前位置:首页 >> python写出九九乘法表 >>

python写出九九乘法表

def multiplicationTable(): for i in range(1, 10): for j in range(1, i): print "%d * %d = %d\t" % (j, i, j * i), print "%d * %d = %d\n" % (i, i, i * i),if __name__ == '__main__': multiplicationTable()

Python 3.6.1 (default, Sep 7 2017, 16:36:03) [GCC 6.3.0 20170406] on linuxType "help", "copyright", "credits" or "license" for more information.>>> print('\n'.join([' '.join([f'{x}*{y}={x*y:2}' for x in range(1, y+1)]) for y in range(1, 10)]))1*1= 11*

首先,你的语法是 python3 的语法,但是用的是 python2;其实,类似这种题目,借助格式化输出会更加方便,看代码:# -*- encoding: gbk -*- for row in range(1, 10): for col in range(1, row + 1): prod = row * col print '%d * %d = %-2d ' % (col, row, prod), print运行:

同学你好, 很高兴能够与你一起学习,共同进步! 以下代码基于Python3实现,请注意区别版本不同带来的影响.for i in range(1, 10): for j in range(1, i+1): print('{}x{}={}\t'.format(i, j, i*j), end='')#格式化输出 print() 希望可以帮助到你,天天晴!

table_9x9.py#! /usr/bin/python# Filename : table_9x9.py# Author : Jesse# Date : 2011/08/13 21:50 print '\n9x9 Table\n' for i in range(1, 10) : for j in range(1, i+1) : print j, 'x', i, '=', j*i, '\t', # print '%d x %d = %d\t' %(j, i, j*i), print '\n' print '\nDone!' 关于

for a in range(1,10): for b in range(1,a+1): print(f'{a}*{b}={a*b}',end=' ') print('') 亲测有效.

i = 0while 1: if i == 5: i = -i + 1 else: i += 1 print('*' * abs(i)) if i == 0:break

首先,你的语法是 python3 的语法,但是用的是 python2;其实,类似这种题目,借助格式化输出会更加方便,看代码:# -*- encoding: gbk -*-for row in range(1, 10): for col in range(1, row + 1): prod = row * col print '%d * %d = %-2d ' % (col, row, prod), print运行:

for i in range (1,10): #两个循环知1-9 与 1-9相乘 for j in range(1,10): print(j,"x",i,"=",i*j,"\t",end="")#输出,道\t是输出后带tab空隔回,end="",表示不断行 if i==j: #该换行答了 print("") #输出空 break #换行

print(str(sec)+"*"+str(first)+"=" + str(sec*first) + "\t")

网站首页 | 网站地图
All rights reserved Powered by www.dfkt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com