友情提示:380元/半年,儿童学编程,就上码丁实验室。
这里 学以致用,使用python解决数学作业中的问题。加深解题思路以及对python的熟悉程度

题目:个位数字比十位数字大2的两位数有哪些?
解题思路:因为是两位数,所以十位只能从1到9变化。把十位从1到9依次遍历,依据个位=十位+2来计算个位,但是个位条件是不能大于9。
for tensplace in range(1,10): onesplace=tensplace+2 if onesplace<10: tensdigit=tensplace*10+onesplace print(tensdigit) else: break 输出结果: 13 24 35 46 57 68 79

如同第一题,只不过条件变成十位比个位大4的两位数。这个时候个位可以从0开始。
for onesplace in range(0,10): tensplace=onesplace+4 if tensplace==10: break re=tensplace*10+onesplace print(re) 输出结果: 40 51 62 73 84 95

题目:十位上的数字和个位上的数字和是10的两位数有哪些。
解题思路:无论是个位还是十位,只能从0到9变换,只不过,如果是两位数,十位不能是0。本题编程的思路使用了遍历所有两位数的思路,即遍历10到99的所有两位数。
s=10 for tensplace in range(0,10): for onesplace in range(0,10): if tensplace+onesplace==s and tensplace!=0: print(tensplace*10+onesplace) 输出结果: 19 28 37 46 55 64 73 82 91

题目:7X( )<68,可以填写的最大数是多少?
解题思路:这种题目考的是乘法,括号里面的数字从0开始,向上遍历,只有满足条件当前数字乘以7小于68,并且下一个数字乘以7大于等于68。这样的数字才满足条件。
for n in range(1,100): if 7*n<68 and 7*(n+1)>=68: print("7*("+str(n)+")<68") break 输出结果: 7*(9)<68

for n in range(1,10): for m in range(1,n+1): print("%s*%s=%s" %(m,n,m*n),end=" ") print() 输出结果: 1*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