Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Newbie. Need help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Joshua Landau, post: 5104267"] Hello. You replied off-list (to me only, not to Python-list). I imagine this was a mistake, so I'm posting to Python-list again. If this wasn't a mistake, then I apologize and suggest telling people when you mean to reply off-list. Also, you top-posted, which isn't the right thing to do. This means you wrote your reply above the copy of the text you were replying to -- you should write below. You should also delete all of the parts that you aren't responding to, so people know what you are talking about. You have done: def main(): pass So you know how to define a *main function*. This should take a parameter. Do you know how to make a function accept a parameter? Once you have that parameter, you need to check whether it is even or odd. If you don't know how to do this, check the link I gave in my last post or try a Google search for "python check number even odd". Knowing how to look for answers to simple (and later complicated) problems is important to being a good programmer. OK, that's good. You know how to generate random numbers (random.randrange), so now you want to define a function. def generate_numbers(): ... You want to *return* a *list* of *random numbers*: list_of_random_numbers = [] for i in range(10): random_number = <make a random number> # You fill this in list_of_random_numbers.append(random_number) then you want to *return* the *list_of_random_numbers*. Do you know how to return values? You know how to generate 10 random even numbers. I know you know this because you have done: You should assign each random number to a name (using "="). *Inside* your loop, you want to do SOME_FILE.write(str(RANDOM_NUMBER)) When I said to put this in the main function, I meant the *function*, not here. This works, but it isn't what people normally do. See how you call "main()" inside here? Thus, when you have the inside "main()" it will get run anyway. Does this make sense? When I said use "with", I mean use "with" *everywhere*, not just here. So you should use this same pattern in the other places you open files. You will need to indent the *whole* of the code that requires use of the file "f" when you do this. Remember that I'm telling you this so that you know what to do, not so you can take the code I give you. I will not give you complete solutions -- if you ask what "5 + 5" is I will show you how to work out "4 + 4", and then you can apply that to the original problem. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Newbie. Need help
Top