擅长:python、mysql、java
<p>这是一个非常基本的程序,上面的所有内容都包含在基本的python中。。</p>
<p>您应该浏览以下链接,如<a href="http://www.swaroopch.org/notes/Python" rel="nofollow">Bytes of Python</a>、<a href="http://www.learnpython.org/" rel="nofollow">LearnPython</a>等</p>
<p>还有更多的教程供您学习和开始。。</p>
<p>这一行接受用户的输入</p>
<pre><code>In [8]: n = raw_input("Enter a number : ")
Enter a number : 5
</code></pre>
<p>这一行在值1到12的集合上迭代,在python中,我们可以使用range函数。。</p>
<p><code>range(1, 13)</code>是否因为它的范围函数在最后一个值之前停止。。</p>
<p>%s是字符串格式语法,类似于C,最后<code>int(n)</code>是因为z输入是字符串格式的,需要将其转换为int才能进行乘法运算</p>
<pre><code>In [9]: for i in range(1,13):
...: print "%s x %s = %s" %(n, i, i*int(n))
...:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
5 x 11 = 55
5 x 12 = 60
</code></pre>