How do I write a script to generate 10 random EVEN numbers and write them to a .txt file?
sandile.mnukwa at gmail.com
Mon Jul 8 14:01:37 CEST 2013
Hi, 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,
-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.
-And lastly to enhance my script to generate 10 random EVEN numbers and write them to a .txt file.
This what I have done so far.
if __name__ == '__main__':
for i in range(10):
print random.randrange(0, 101, 2)
with open ("C:\Users\Kenz09\Documents\Myproj.txt", "w") as f:
f = open("C:\Users\Kenz09\Documents\Myproj.txt", "a");
value = (
random.randrange (0, 101, 2),
random.randrange(0, 201, 2),
random.randrange(0, 301, 2)
More information about the Python-list