Newbie. Need help

Sanza101 sandile.mnukwa at gmail.com
Mon Jul 8 10:53:06 CEST 2013


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()



More information about the Python-list mailing list