for multiplier in range(5,8): for i in range(1,11): print i ,"x",multiplier,"=",i*multiplier print
#
我尝试将第2个for与第一个for对齐,但是程序就报错了
我的理解,如果拉齐后,就代表第二个程序块成为一个独立的程序块进行运行,这样print计算的时候就无法得到multplier的值,所以就无法完成计算
#result
C:\Python27\python.exe C:/Users/hunk/PycharmProjects/untitled/guess-number.py 1 x 5 = 5 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 6 x 5 = 30 7 x 5 = 35 8 x 5 = 40 9 x 5 = 45 10 x 5 = 50 1 x 6 = 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 54 10 x 6 = 60 1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 7 x 7 = 49 8 x 7 = 56 9 x 7 = 63 10 x 7 = 70
原文地址:http://huzhongliang.blog.51cto.com/1817180/1891965