How can I write this C code in Python?
Luigi Ballabio
ballabio at mac.com
Sat Feb 2 10:25:27 EST 2002
At 7:10 AM -0800 2/2/02, Fred wrote:
>Hello, I am just starting out with Python. I have a very basic book
>that is not helping me much. I have done some simple C programming in
>the past and I think if I could see the below C code done in Python it
>would get me over the beginners hump. I tried to do it in Python but
>got stuck right at the start, Python did not like it when I tried to
>say: for i = 1
Fred,
I think you can find more info and tutorials at www.python.org.
Anyway, the for loops you are trying to write ca nbe expressed as:
for i in range(1,13): # 1 is included, 13 is not
for j in range(1,13):
print "%4d" % (i*j), # the comma at the end inhibits line breaks
print # "print" alone prints a newline
Happy coding,
Luigi
>//Simple C code to create a times table.
>
>#include <stdio.h>
>int main (void)
>
>{
>
>int i;
>int j;
>
>for (i = 1; i < 13; i++)
> {
> for (j = 1; j < 13; j++)
> printf("%4d", i*j);
> printf("\n");
> }
>return 0;
>}
>--
>http://mail.python.org/mailman/listinfo/python-list
--
More information about the Python-list
mailing list