龙空技术网

学python(二年级加减法)

大布1205 138

前言:

现时看官们对“python 减法”大致比较讲究,朋友们都需要学习一些“python 减法”的相关知识。那么小编在网络上汇集了一些有关“python 减法””的相关文章,希望看官们能喜欢,你们快快来了解一下吧!

儿子二年级口算不过关,没办法,只能天天练习...

学习用python3生成随机100以内口算题,运行后可以在当前目录生成一个“口算100.doc”的文件,已排版,直接打开打印即可:

脚本如下:

# -*- coding: utf-8 -*-import randomdef run():    file1 = open('口算100.doc','w',encoding='utf-8')    file1.write("口算\n\n")    i = 1    while i <= 160:        firstnum = random.randint(1,100)        secondnum = random.randint(1, 100)        pp = random.randint(1,2)        if ( pp == 1 ):            if ((firstnum + secondnum) < 100):                print("{0:6}{1:3}+ {2:3}=    |".format("("+str(i)+")",str(firstnum),str(secondnum)),end=" ",file=file1)                i+=1                if ( i % 4 == 1 ):                    file1.write("\n")        elif ( pp == 2):            if( firstnum > secondnum):                print("{0:6}{1:3}- {2:3}=    |".format("("+str(i)+")",str(firstnum),str(secondnum)),end=" ",file=file1)                i+=1                if ( i % 4 == 1 ):                    file1.write("\n")            else:                print("{0:6}{1:3}- {2:3}=    |".format("("+str(i)+")",str(secondnum),str(firstnum)),end=" ",file=file1)                                                 i+=1                if ( i % 4 == 1 ):                    file1.write("\n")    file1.close()if __name__=="__main__":    run() 

标签: #python 减法 #python怎么加法