一、所用知識點:
1.變量的使用。
2.循環語句的使用,這里用到的是雙while循環。當然,使用其他的循環去做也是可以的。我認為,對於剛剛接觸編程的人來說,使用雙while循環比較容易理解。
3.使用了換行符“\n”和制表符“\t”,使輸出效果更加的美觀
二、代碼:
1 print("\n"+"From top to bottom") 2 3 a1 = 1 4 5 while a1 <= 9: 6 a2 = 1 7 while a2 <= a1: 8 print(str(a2)+"*"+str(a1)+"="+str(a1*a2), end = "\t") 9 a2 = a2 + 1 10 print() 11 a1 = a1 + 1 12 13 print("######################################################################\n") 14 15 print("From bottom to top") 16 17 a3 = 9 18 19 while a3 > 0: 20 a4 = 1 21 while a4 <= a3: 22 print(str(a4)+"*"+str(a3)+"="+str(a3*a4),end = "\t") 23 a4 = a4 +1 24 print("") 25 a3 = a3 - 1
三、效果輸出: