help!!!

G

Guest

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....
 
D

Diez B. Roggisch

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....

For such an aspiring student of the art of computer programming, I have
the strange feeling of lack-of-effort-showing here. Do I have to lose my
faith in youth?

Diez
 
E

Emile van Sebille

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....

For such an aspiring student of the art of computer programming, I have
the strange feeling of lack-of-effort-showing here. Do I have to lose my
faith in youth?[/QUOTE]


Oh come now -- isn't being lazy a primary programmer's attribute?

:)

Emile
 
S

Seebs

For such an aspiring student of the art of computer programming, I have
the strange feeling of lack-of-effort-showing here. Do I have to lose my
faith in youth?

Never!

Just be sure you are having faith in them to, well, be youth. :)

-s
 
S

Steven D'Aprano

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....

Good grief. It's bad enough to expect us to do your coding for you,
without making even the *tiniest* effort to learn yourself, but then to
add insult to injury you use text-speak.

ur nt sending sms now, learn to rite the wrds

If you want to learn Python, I suggest you work through some tutorials.
Google is your friend: google on "python tutorial" and see what comes up.
 
D

Diez B. Roggisch

Seebs said:
Never!

Just be sure you are having faith in them to, well, be youth. :)

I took the freedom to google a bit. If one can trust people on the
inter-tubes (and who would have heard you can't?), he's a rather skilled
student

http://www.aboutrafi.net23.net/

With an impressive amount of technological experience under his belt. So
I'm a bit aghast to see him struggle with this rather simple
problem. Thus my question...

Diez
 
S

Seebs

With an impressive amount of technological experience under his belt. So
I'm a bit aghast to see him struggle with this rather simple
problem. Thus my question...

It does seem a bit odd.

I mean, if I had a short time line to get something converted to Python,
I'd probably ask for help, but then, I wouldn't take a gig where I needed to
quickly move something into an unfamiliar language. I'm happily puttering
away slowly at converting a couple of things to Python to get the hang of it,
carefully selecting things with no impending deadlines.

Thus far, I've converted a shell script to Python. It was... well, shell
turned out to be a poor language for it, but I do note that the shell
script, including all the here documents, was quite a bit smaller than the
Python. On the other hand, I think the Python script is a lot more
maintainable, and this despite me not really knowing the language particularly
well. It's an interesting tradeoff. Still getting used to the Python
way of doing things.

-s
 
D

Diez B. Roggisch

Seebs said:
It does seem a bit odd.

I mean, if I had a short time line to get something converted to Python,
I'd probably ask for help, but then, I wouldn't take a gig where I needed to
quickly move something into an unfamiliar language. I'm happily puttering
away slowly at converting a couple of things to Python to get the hang of it,
carefully selecting things with no impending deadlines.

From the look of it... he's just trying to get a freebie on a homework
assignment. It certainly is no commercial/useful piece of code
whatsoever... just CS-101 "read data from stdin and do stuff".

Diez
 
S

Seebs

From the look of it... he's just trying to get a freebie on a homework
assignment. It certainly is no commercial/useful piece of code
whatsoever... just CS-101 "read data from stdin and do stuff".

Ooh, I should go help, then.

I *love* to help people on homework. Although I may not know Python
well enough.

I once responded to a request for a thing that, given a number, says
something like "The first digit is 3, the second digit is 2" with a program
that included a partial table of ln(x) for about 30 values between 0 and
900... It worked, though!

-s
 
G

Grant Edwards

Good grief. It's bad enough to expect us to do your coding for you,
without making even the *tiniest* effort to learn yourself, but then to
add insult to injury you use text-speak.

ur nt sending sms now, learn to rite the wrds

LOL!

I was particularly impressed by the pithy subject line. The extra
exclamation points are always the hallmark of the clueless and rude.
 
S

Seebs

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:

#include<cstdio>

int main()
{
int a[100], n;
freopen("input.txt", "r", stdin);
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%d", &a);
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
incorrect.

-s
 
D

Dennis Lee Bieber

#include<cstdio>

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

This was supposed to be C++? Not a single C++ style I/O operation in
sight...

And even as C... Rather than use fscanf() they've reopened stdin on
a file?!?!

And what happened to argc, argv?

No comments on the lack of bounds checking...
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
incorrect.

I'm not quite that cruel...

Try this one (untested):

--------------- homework.rx
/* this is not Python */
FILENAME = "input.txt"
n = linein(FILENAME)
do i = 1 to n
a.i = linein(FILENAME)
end
exit 0
 
J

John Nagle

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:

#include<cstdio>

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


This guy doesn't know C very well, either.

First, "scanf" was deprecated over five years ago.
And reopening "stdin" is rarely done, although
it is possible.

Second, there's a buffer overflow. "n" is obtained
from external input, then used to control the "for"
statement. If N is >= 99, there will be a buffer
overflow on "a". Also, starting to fill "a" from 1
looks like an error.

Third, the program doesn't actually do anything.
There's no output.

It looks like this approach to C came from

http://beej.us/guide/bgc/output/html/multipage/freopen.html

John Nagle
 
S

Seebs

First, "scanf" was deprecated over five years ago.

It was? I mean, people have been telling me not to use it since the 80s,
but I wasn't aware that it had been deprecated, except in the sense of being
derided and dismissed as of no value.

-s
 
L

Lawrence D'Oliveiro

Emile van said:
Oh come now -- isn't being lazy a primary programmer's attribute?

I wonder if that’s why more men are good at it than women...
 
A

Andreas Waldenburger

I wonder if that’s why more men are good at it than women...

You may want to think about whether this really was your intended
meaning.

/W
 
R

Robert Kern

You may want to think about whether this really was your intended
meaning.


Sure it was -- men are lazy; programmers are primarily lazy; explains why
programmers are predominantly men (for the time being, at least). Made perfect
sense to me.

That's quite a different statement than "men are more good at it than women".

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
R

Robert Kern

On Mon, Oct 11, 2010 at 11:11 AM, Robert Kern <[email protected]

On 10/11/10 8:44 AM, Jason Swails wrote:



On Mon, Oct 11, 2010 at 9:25 AM, Andreas Waldenburger
<[email protected]>
wrote:


<mailto:[email protected]>
<mailto:[email protected]


You may want to think about whether this really was your intended
meaning.


Sure it was -- men are lazy; programmers are primarily lazy; explains why
programmers are predominantly men (for the time being, at least). Made
perfect
sense to me.


That's quite a different statement than "men are more good at it than women".


Since when have programmers argued semantics/syntax?

It's *all* we argue about. That, and tabs vs. spaces.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top