Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50145

Re: Newbie. Need help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!newsfeeder.ewetel.de!eweka.nl!lightspeed.eweka.nl!69.16.177.246.MISMATCH!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!npeersf03.am4!fx30.am4.POSTED!not-for-mail
From Alister <alister.ware@ntlworld.com>
Subject Re: Newbie. Need help
Newsgroups comp.lang.python
References <7aa32d52-8f91-4ffc-8e0d-3be769cd0e33@googlegroups.com>
User-Agent Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Lines 66
Message-ID <TIxCt.1445$HO4.367@fx30.am4> (permalink)
NNTP-Posting-Host 82.18.78.222
X-Complaints-To http://netreport.virginmedia.com
X-Trace 1373284275 82.18.78.222 (Mon, 08 Jul 2013 11:51:15 UTC)
NNTP-Posting-Date Mon, 08 Jul 2013 11:51:15 UTC
Organization virginmedia.com
Date Mon, 08 Jul 2013 11:51:15 GMT
X-Received-Bytes 2675
Xref csiph.com comp.lang.python:50145

Show key headers only | View raw


On Mon, 08 Jul 2013 01:53:06 -0700, Sanza101 wrote:

> I just started using Python recently, and i need help with the
> following: Please assist.
> 
> 1.	Create another function that generates a random number (You will 
have
> to import the relevant library to do this)
> 2.	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 3.
> Now enhance your script to generate 10 random even numbers and write
> them to a file
> 
> So far what i have done is:
> import random def main():
>     pass
> 
> if __name__ == '__main__':
>     main()
> for evenNumber in range (0, 20, 2):
>     print random.randrange(0, 101, 2)
> 
> f = open("C:\Users\Documents\Myproj.txt", "w");
> print f f = open("C:\Users\Documents\Myproj.txt", "a");
> print f
> 
> value = random.randrange(0, 101, 2, )
> value1 = random.randrange(0, 201, 2, )
> value2 = random.randrange(0, 301, 2, )
> 
> myString = str(value)
> myString1 = str(value1)
> myString2 = str(value2)
> 
> print f.write(myString)
> print f.write(myString1)
> print f.write(myString2)
> f.close()
As this is course work I wont give you answers just pointers to help.

from the wording of the question your teacher is probably more interested 
in you understanding how to define functions.

so from the design requirements you will need something like

def get_random():
	#your code foes here

def is_even(number):
	#you code here

you then need to loop through the code writing to file each time you get 
an even result.

a for loop is probably not the best type of loop for this task.

once you have some more code I am sure we will help further if you get 
stuck with any specifics.



-- 
The computer is to the information industry roughly what the
central power station is to the electrical industry.
		-- Peter Drucker

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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