1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Rep Power

    *Random Number File Writer* help

    Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers the file will hold. This is what i have so far.

    # This program displays five random
    # numbers in the range of 1 through 100.
    import random

    def main():
    for count in range():
    # Get a random number.
    number = random.randint(1, 100)
    # Display the number.

    # Call the main function.

    How do i change this so the user can specify how many numbers will show?
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    # source for prompt is in post 4 of http://forums.devshed.com/python-programming-11/newbie-question-regarding-exceptions-933626.html
    def positive_integer(s):
        rv = int(s)
        if rv < 0: raise ValueError()
        return rv
    for count in range(prompt('How many random numbers? ',conversion=positive_integer,default=1)):
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo