Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50130
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-07-08 01:53 -0700 |
| Message-ID | <7aa32d52-8f91-4ffc-8e0d-3be769cd0e33@googlegroups.com> (permalink) |
| Subject | Newbie. Need help |
| From | Sanza101 <sandile.mnukwa@gmail.com> |
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()
Back to comp.lang.python | Previous | Next — Next 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