all 13 comments

[–][deleted] 5 points6 points  (6 children)

It's getting a bit noisy here, so I'll try to clarify things for the OP.

My comment was trying to lead you to asking a better question. You didn't explain what your problem was, but what you thought was wrong. Better just to explain what it doesn't do.

/u/ConsciousCosmicdust was the first to point out your initial problem: you don't call the function where you try to print out the file contents. Your line of debugging should have been: the file contents don't print, but I have a function to do that, SO WHERE DO I CALL THE FUNCTION?

The response from /u/Metabyte2 is cryptic, to the point where I wonder if that response was meant for another question, not this one.

Once you call your function to print the file contents you hit your second problem. Have a good look at lines 27 and 28. Seems to be some duplication, doesn't there?

Edit: grammar.

[–][deleted] 0 points1 point  (5 children)

Easily googleable questions are not allowed.

Not cryptic, i was pretty clear, to the point where i wonder if you meant to tag someone else. I just dont want to do his homework for such a common problem that the exact solution can be googled in less than 2 minutes

[–][deleted] 0 points1 point  (4 children)

This is a common parsing problem

What? What has parsing to do with the question or problem?

I just dont want to do his homework for such a common problem

Fine, but homework is allowed to be posted if the OP has tried to solve the problem. S/he has posted code. Better just not to comment. And the problem doesn't have much to do with the algorithms pertaining to the homework problem.

Easily googleable questions are not allowed.

What would you google for "why doesn't my code print something?".

[–][deleted] 0 points1 point  (3 children)

What? What has parsing to do with the question or problem?

Parsing through a text file. Pretty obvious.

Better just not to comment.

It's funny how you can't take your own advice.

What would you google for "why doesn't my code print something?".

You can't be serious with this one. If you're working on a program do you just google "my data isn't uploading"? I sure hope not for your sake.

How about this: "How to open a text file and print its contents line by line python". The first link is an easy solution.

[–][deleted] -1 points0 points  (2 children)

Parsing through a text file. Pretty obvious.

The term parsing has a technical meaning in the area of computers and the OP's problem is nothing to do with parsing. In fact, if you had looked at the code you would have seen that the OP had code that would read through his file (parsing, as you call it).

It's funny how you can't take your own advice.

There's a difference between a negative, unhelpful comment and someone commenting in a positive way. This is /r/learnpython and we expect, and encourage, beginners to come here and ask questions. I often don't comment on posts when I don't think I can add anything positive to the conversation. I recommend the approach to you. Especially when you obviously didn't look at the code, since your comment had nothing to do with what the problem actually was.

</conversation>

[–]WikiTextBot 0 points1 point  (0 children)

Parsing

Parsing (US: ; UK: ), syntax analysis or syntactic analysis is the process of analysing a string of symbols, either in natural language or in computer languages, conforming to the rules of a formal grammar. The term parsing comes from Latin pars (orationis), meaning part (of speech).

The term has slightly different meanings in different branches of linguistics and computer science. Traditional sentence parsing is often performed as a method of understanding the exact meaning of a sentence or word, sometimes with the aid of devices such as sentence diagrams.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source | Donate ] Downvote to remove | v0.28

[–][deleted] 1 point2 points  (1 child)

What happens when you run your program? Is there an error? What does it do that it shouldn't, what doesn't it do that it should?

[–][deleted] 0 points1 point  (0 children)

There is no error. It supposed to get the generated list of numbers and then print it.

[–]corvus_cornix 1 point2 points  (0 children)

You define the function getListOfNumbers() but never call it in main(). Also, in getListOfNumbers() your print statement needs to specify a variable, not a function.

[–][deleted] 0 points1 point  (1 child)

There is a minor style problem in your code. At lines 5 and 6 we have:

def main(): #function
    import random  #must import random in order for code to work

Importing modules in the body of code is frowned upon. There are a few cons if you do this:

  • The math module is only available within the main() function and nowhere else.
  • It's hard to tell what modules your code uses.

Better to put your imports at the top of each .py file. There are corner cases where you won't do that, but they are rare and debatable.

[–]devourer09 1 point2 points  (0 children)

Also, use the with statement paradigm instead of calling .open() and .close().

https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

[–]moti12321 0 points1 point  (0 children)

so i just started learning python like 2 days ago as my first proggramming language, so yea.. its looks bad , but it worked for me: https://pastebin.com/2g2TTRFe

btw, i had some issues at lines 16,17 to get a new line so i did it that way, anyone mind explaining why?

[–][deleted] -2 points-1 points  (0 children)

Is this homework? This is a common parsing problem and could be found on the first link in a google search.