Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50152
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; '-to': 0.05; 'anyway.': 0.05; '(using': 0.07; 'assign': 0.07; 'only,': 0.07; 'responding': 0.07; 'subject:help': 0.08; '__name__': 0.09; 'f.close()': 0.09; 'function,': 0.09; 'here?': 0.09; 'main()': 0.09; 'parameter': 0.09; 'replied': 0.09; 'thus,': 0.09; 'def': 0.12; 'suggest': 0.14; 'wrote': 0.14; 'random': 0.14; '","': 0.16; '"f"': 0.16; '"python': 0.16; '"w")': 0.16; '"with"': 0.16; "'__main__':": 0.16; '(0,': 0.16; '-create': 0.16; '.txt': 0.16; '2),': 0.16; 'accepts': 0.16; 'determines': 0.16; 'indent': 0.16; 'main():': 0.16; 'parameter.': 0.16; 'separated': 0.16; 'values?': 0.16; 'files.': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'basically': 0.19; 'normally': 0.19; 'later': 0.20; 'meant': 0.20; 'programming': 0.22; 'import': 0.22; 'print': 0.22; "aren't": 0.24; 'file.': 0.24; 'script': 0.25; 'define': 0.26; 'task': 0.26; 'pass': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'function': 0.29; '(this': 0.29; 'skip:( 40': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'posting': 0.31; '-and': 0.31; 'about.': 0.31; 'file': 0.32; 'this.': 0.32; 'run': 0.32; 'another': 0.32; 'text': 0.33; 'open': 0.33; 'to:name:python-list': 0.33; 'problem.': 0.35; 'skip:s 30': 0.35; 'good.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'done': 0.36; 'next': 0.36; 'thanks': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'being': 0.38; 'problems': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'number,': 0.60; 'most': 0.60; 'new': 0.61; 'numbers': 0.61; 'skip:* 10': 0.61; 'simple': 0.61; 'you.': 0.62; 'complete': 0.62; 'show': 0.63; 'name': 0.63; 'july': 0.63; 'places': 0.64; 'subject:Need': 0.64; 'telling': 0.64; 'talking': 0.65; 'to:addr:gmail.com': 0.65; 'reply': 0.66; 'subject:. ': 0.67; 'below.': 0.71; 'to,': 0.72; '301,': 0.84; 'done:': 0.84; 'imagine': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=kfjFCiPDA5giASo6UVTB1dThVTh9/iHi0N8104oM2iE=; b=WVz6HLggqZJLtyTnycp2GK4+Hf9ZvV65Rnyj2zJag3rJaHbFQ7H3t37hDHjs2JpGzz kcXrSC6oDdXGUErIkgnXY5oIwSgJ0mEzWWThjwo6tjf+/udF3cVBx//NASHfggMcavlf JFdcuP28o3rqRhNzDL6zyT4nc6lTjfpJ+J//GaqbniwUemLJHrWMrpHFM9Gz6fldxNQZ rGJhHyyEmU4w3jZ5Tb4V7yLgw/bgvjONnp3jQVhby9SG+MNHy4XYzHgJdPovZzDF6+ip YFT3IHfHZCiKV8ZAunpl/8R+gm5rdiW1HquUHkOmCMsJtLj2P5bWgdTFO5PP147mdjhE DBcA== |
| X-Received | by 10.112.52.97 with SMTP id s1mr10710976lbo.8.1373288565964; Mon, 08 Jul 2013 06:02:45 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <FD157D1A-53E3-4598-A9D4-F529EE7473A0@gmail.com> |
| References | <7aa32d52-8f91-4ffc-8e0d-3be769cd0e33@googlegroups.com> <CAN1F8qWr6pmjf+1CoVvuNTJx4vx=AFmwgfXQizL3xiVNxu+25w@mail.gmail.com> <FD157D1A-53E3-4598-A9D4-F529EE7473A0@gmail.com> |
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
| Date | Mon, 8 Jul 2013 14:02:04 +0100 |
| Subject | Re: Newbie. Need help |
| To | sandile.mnukwa@gmail.com, python-list <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4385.1373288573.3114.python-list@python.org> (permalink) |
| Lines | 120 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1373288573 news.xs4all.nl 15923 [2001:888:2000:d::a6]:36730 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50152 |
Show key headers only | View raw
On 8 July 2013 13:05, Sandile Mnukwa <sandile.mnukwa@gmail.com> wrote:
> Hi Joshua,
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.
> Thanks for the help so far.
> Just been panicking about learning the language...
>
> I have been given a task to do. I am a new to programming and Python.
> My task is to :
> -Create a function that is called from the main function, that accepts a number as a parameter and determines if the number is even or odd.
> the next one is,
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.
> -To create another function that generates a random number, and basically when i print this function, it should give me a list of random number separated by a "," commma or in a list.
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?
> -And lastly to enhance my script to generate 10 random EVEN numbers and write them to a .txt file. (This task is the most important of them all)
You know how to generate 10 random even numbers. I know you know this
because you have done:
> for i in range(10):
> print random.randrange(0, 101, 2)
You should assign each random number to a name (using "=").
*Inside* your loop, you want to do SOME_FILE.write(str(RANDOM_NUMBER))
> What I have done so far.
>
> import random
>
> if __name__ == '__main__':
> main()
> for i in range(10):
> print random.randrange(0, 101, 2)
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
> for i in range(10):
> print random.randrange(0, 101, 2)
inside "main()" it will get run anyway. Does this make sense?
> with open ("C:\Users\Kenz09\Documents\Myproj.txt", "w") as f:
> print f
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.
> f = open("C:\Users\Kenz09\Documents\Myproj.txt", "a");
> print f
>
> value = (
> random.randrange (0, 101, 2),
> random.randrange(0, 201, 2),
> random.randrange(0, 301, 2)
> )
>
> random_numbers[0]
> random_numbers[1]
> random_numbers[2]
>
> print f.write(str(value))
> print f.write(str(value1))
> print f.write(str(value2))
> f.close()
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Newbie. Need help Sanza101 <sandile.mnukwa@gmail.com> - 2013-07-08 01:53 -0700 Re: Newbie. Need help Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-08 11:28 +0100 Re: Newbie. Need help Alister <alister.ware@ntlworld.com> - 2013-07-08 11:51 +0000 Re: Newbie. Need help Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-08 14:02 +0100
csiph-web