Seebs usenet-nospam at
Thu Oct 7 05:02:23 CEST 2010

On 2010-10-06, <fkrafi at> <fkrafi at> wrote:
> plz can u convert this cpp file into python i need that badly as soon as
> possible... I am new to python. I just wanna learn it....

Having come to realize that this is a homework problem, I would of course
be glad to.

The original program:


	int main()
	    int a[100], n;
	    freopen("input.txt", "r", stdin);
	    scanf("%d", &n);
	    for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	    return 0;

So, let's convert this.

	#!/usr/bin/python -w
	import cstdio;

	def main():
	    a = [random.randint(-2147483648,2147483647) for i in range(0,100)]
	    n = random.randint(-2147483648)
	    sys.stdin = open("input.txt", "r")
	    raise IndexError

I'm not sure how much good this will do you.  It seems to me that you
might get better results translating a program which was not obviously

Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam at <-- lawsuits, religion, and funny pictures <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

More information about the Python-list mailing list