1.输入一个5位数字,判断其位数:val = input("please input a 1-99999 number:")vals = int(val)if vals >= 1000: if vals >=10000: print("This is 5") else: print("This is 4")else: if vals >= 100: print("This is 3") else: if vals >= 10: print("This is 2") else: print("this is 1")
2.输入一个数字打印乘法表:A = input("please input you`r Num:")NUM = int(A)sum = 0for i in range(1,NUM+1): for j in range(i,NUM+1): sum =i*j print(str(i) + "x" + str(j)+"=" + str(sum)+"\t",end=" ") #print(str(i) + "*" + str(j)+"=" + str(sum)) print()
please input you`r Num:91x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 6x6=36 6x7=42 6x8=48 6x9=54 7x7=49 7x8=56 7x9=63 8x8=64 8x9=72 9x9=81
输入一个数字输出乘法表:A = input("please input you`r Num:")NUM = int(A)sum = 0for i in range(1,NUM+1): for j in range(1,i+1): sum =i*j print(str(j) + "*" + str(i)+"=" + str(sum)+"\t",end=" ") #print(str(i) + "*" + str(j)+"=" + str(sum)) print()
please input you`r Num:91*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
九九乘法表,不一样的表示:for i in range(1,10): line = '' for j in range(1,10): if i > j: line = '{} {}{:<4}'.format('','','') else: line = '{}*{}={:<4}'.format(i,j,i*j) print(line,end=' ') print()
3.输如一个数字求其阶乘之和:如果输入3:和=1x1+1x1x2+1x1x2x3n = int(input("please input you`r num:"))a = 1sum = 0for i in range(1,n+1): for j in range(1,i+1): a *= j #print("--->a"+ "+"+str(a)) sum += a a = 1print(sum)
please input you`r num:39
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦