此用户不合法
发表于 2018-3-17 12:22:15
dictnum = {0:'',1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",10:"十"}
for i in range(1,10):
for j in range(1,i+1):
if i*j<10:
print(dictnum+dictnum+'得'+dictnum,end = ' ')
else:
print(dictnum+dictnum+dictnum[(i*j)//10]+dictnum+dictnum[(i*j)%10],end = ' ')
print("\n")
tsembrace
发表于 2018-3-17 12:34:24
'''
打印中文九九乘法表
要求使用循环语句或等同于循环的方法。
'''
dictcf={0:'',1:'一',2:'二',3:'三',4:'四',5:'五',6:'六',7:'七',8:'八',9:'九'}
for i in range(1,10):#行标
for j in range(1,i+1):#列标
if i*j>9:
strjg=dictcf+'十'+dictcf
strx=' '
if i*j%10==0:
strx=' '
else:
strjg='得'+dictcf
strx=' '
print(dictcf+dictcf+strjg,end=strx)
print()
8306最硬
发表于 2018-3-17 12:53:13
lst = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
for i in range(1, 10):
for j in range(1, i + 1):
n = i * j
if n < 10:
print('{}{}得{:<2}'.format(lst, lst, lst), end = ' ')
elif n % 10 != 0:
print('{}{}{}十{}'.format(lst, lst, lst, lst), end = ' ')
else:
print('{}{}{}十'.format(lst, lst, lst), end = ' ')
print('\n')
°蓝鲤歌蓝
发表于 2018-3-17 13:06:27
本帖最后由 °蓝鲤歌蓝 于 2018-3-17 13:08 编辑
List = ['','一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
a = {x:y for x, y in enumerate(List)}
for i in range(1, 10):
for j in range(1, i+1):
if i*j <= 10:
b = '{}{}得{}'.format(a, a, a)
print(b, end=' '*(8-len(b)))
else:
c = '{}{}{}'.format(a, a, a+'十'+a)
result = a+'十'+a
print(c, end=' '*(7-len(c)))
print()
一一得一
一二得二 二二得四
一三得三 二三得六 三三得九
一四得四 二四得八 三四一十二四四一十六
一五得五 二五得十 三五一十五四五二十 五五二十五
一六得六 二六一十二三六一十八四六二十四五六三十 六六三十六
一七得七 二七一十四三七二十一四七二十八五七三十五六七四十二七七四十九
一八得八 二八一十六三八二十四四八三十二五八四十 六八四十八七八五十六八八六十四
一九得九 二九一十八三九二十七四九三十六五九四十五六九五十四七九六十三八九七十二九九八十一
中文 对不齐,很怪。
阿bang
发表于 2018-3-17 18:12:50
# ! /urs/bin/env python
# coding=utf-8
# __author__ = 'bang'CreateDate:2018/3/17
chinese = {1: '一',
2: '二',
3: '三',
4: '四',
5: '五',
6: '六',
7: '七',
8: '八',
9: '九'
}
# print by number
# for i in range(1, 10):
# for j in range(1, i + 1):
# cal = i * j
# print j, '*', i, '=', '%-3d' % cal,
# print
# print by chinese
for i in range(1, 10):
for j in range(1, i + 1):
cal = i * j
if cal < 10:
print '%-8s' % (chinese + chinese + '得' + chinese),
elif cal % 10 == 0:
print '%-8s' % (chinese + chinese+ chinese + '十'),
else:
print '%-10s' % (chinese + chinese + chinese + '十' + chinese),
print
输出得格式,搞了占位符,也搞不定。新人求版主指教。
Dwfox
发表于 2018-3-17 20:49:24
1
Chase_Kas
发表于 2018-3-17 21:10:59
本帖最后由 Chase_Kas 于 2018-3-17 21:22 编辑
确实比想象的要简单些,两个循环嵌套就行了
def fun():
num = ' 一二三四五六七八九'
for i in range(1, 10):
for j in range(1, i + 1):
if i*j < 10:
print((num + num + '得' + num + ' ').ljust(7), end = '')
else:
print((num + num + num + '十' + num).ljust(7), end = '')
print()
fun()
Chase_Kas
发表于 2018-3-17 21:11:59
多回一贴领奖励嘿嘿嘿
luokaoge
发表于 2018-3-17 21:13:51
本帖最后由 luokaoge 于 2018-3-17 21:15 编辑
{:9_230:}又晚啦,手机打还是不太方便呀{:9_239:}
for i in range(1,10):
x=i
s = []
c = ''
d = ['十','一','二','三','四','五','六','七','八','九']
for i in range(1,x+1):
y=str(i*x)
a = d
b = d
e = d)]
f = ''
if len(y)==2:
if int(y)==0:
f = d + ''
else:
f = d + d)]
c = a + '乘' + b + '得' + e + f
else:
c = a + '乘' + b + '得' + e + ' '
s.append(c)
print(" ".join(s))
luokaoge
发表于 2018-3-17 21:14:25
本帖最后由 luokaoge 于 2018-3-17 21:30 编辑
这样还是格式好看些{:9_237:}
for i in range(1,10):
x=i
s = []
c = ''
d = ['十','一','二','三','四','五','六','七','八','九']
for i in range(1,x+1):
y=str(i*x)
a = d
b = d
e = d)]
f = ''
if len(y)==2:
if int(y)==0:
f = d + ''
else:
f = d + d)]
c = a + '乘' + b + '得' + e + f
else:
f = ' '
if i == 1:
c =a + '乘' + b + '得' + e
else:
c =a + '乘' + b + '得' + e + f
s.append(c)
print(" ".join(s))
被翻红浪
发表于 2018-3-17 21:34:51
def mul(n):
nums = "一二三四五六七八九十"
for i in range(n):
result = n * (i + 1)
if result < 10:
print("{}{}得{}".format(nums, nums, nums), end=' ')
else:
tens, ones = divmod(result, 10)
if not ones:
print("{}{}{}十".format(nums, nums, nums), end=' ')
else:
print("{}{}{}十{}".format(nums, nums, nums, nums), end=' ')
for i in range(1, 10):
mul(i)
print('\n')
Lis
发表于 2018-3-17 22:01:33
def trans(n):
res = ''
if n // 10:
res += list + list
res += list
return res
list = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
for i in range(1, 10):
for j in range(1, i + 1):
print(list, end = '')
print(list, end = '')
if len(trans(i * j)) == 1:
print('得', end = '')
print(trans(i * j), end = '\t')
print()
lyjlyj
发表于 2018-3-17 23:51:13
def get_new_str(i, item):
'''组合得到新的字符串'''
s = ['一',"二","三","四","五","六","七","八","九"]
#观察可得到,分两种情况:1.当两个数相乘小于10,会有得这个字
#2.当两个数相乘大于10的时候,又分为两种情况:结果是三个字和两个字
#如二五一十 (能被十整除),结果一十是两个字,三五一十五(不能被十整除),结果是三个字
if i * item < 10:
return s+s+"得"+s
else:
if i*item%10 == 0:
return s+s+s+"十"
else:
return s+s+s+"十"+s
def main():
for i in range(1,10):
for item in range(1,i + 1):
new_str = get_new_str(i,item)
print new_str+'\t',
print("")
if __name__ == "__main__":
main()
125zl
发表于 2018-3-18 01:04:56
def cn(n):
list_cn = ['一','二','三','四','五','六','七','八','九','十']
if n <= 9:
return '得' + list_cn
elif n % 10 == 0:
return list_cn + list_cn
else:
return list_cn + list_cn + list_cn
list_cn = ['一','二','三','四','五','六','七','八','九','十']
list_pt = []
str2 = ''
for i in range(9):
for j in range(i + 1):
num = (i + 1) * (j + 1)
str1 = list_cn + list_cn + cn(num)
while(len(str1) < 7):
str1 += ''
str2 += str1
print(str2)
str2 = ''
list_pt = []
lj961005
发表于 2018-3-18 07:47:19
qqq
headmk
发表于 2018-3-18 08:18:11
zhedaan
nononoyes
发表于 2018-3-18 10:48:00
dict1 = {0:'十',1:'一',2:'二',3:'三',4:'四',5:'五',6:'六',7:'七',8:'八',9:'九',}
def fun(a,b):
result = a*b
#求十位数
k = result//10%10
#求个位数
l = result%10
if(k<=0):
return dict1
elif(l!=0):
return dict1+dict1+dict1
else:
return dict1+dict1
m=1
while m<=9:
for i in range(1,m+1):
print('%2s%2s得%2s'%(dict1,dict1,fun(i,m)),end='\t')
print()
m+=1
jiamin_2010
发表于 2018-3-18 14:42:02
um = ("一","二","三",\
"四","五","六"
,"七",\
"八","九","十")
for i in range(0,9):
for j in range(0,i+1):
mul = (i +1)*(j+1)
# print(mul)
if mul <= 10:
mul2str = "得"+num+" "
if i >0:
mul2str += ""
# print(mul2str)
else:
mul2str = num+\
num[-1]+num+" "
# print(mul2str)
toprit = num+num+mul2str
print(toprit,end = " ")
print()
冬雪雪冬
发表于 2018-3-18 20:30:03
评分截至标记。
shigure_takimi
发表于 2018-3-18 21:18:02
大家都写的很简洁呀,向你们学习。