One last python programming question

Discussion in 'Mac Programming' started by iHerzeleid, Mar 14, 2008.

  1. macrumors 6502a


    May 5, 2007
    ok this is my last one and i am still a total n00b to this.
    this is my assigment:

    i have something like this so far:
    someone want to kick me in the right direction? i pretty much have to teach myself this because the professor doesn't really explain any of this.
  2. macrumors member

    Feb 17, 2008
    The bottom of the assignment tells you pretty much exactly what to do, it just doesn't code it for you. What are you having trouble with specifically?
  3. macrumors 6502

    Nov 23, 2005
    So the user is going to enter in the amount of random numbers they would like generated? So I would do that with the following:

    times = raw_input("Number of random numbers to generate > ");
    num_times = int(times); // This method way is assuming the user entered in something that is numeric, you could do a try catch block to ensure this.
    values = [];
    while ( num_times > 0 ) {
    //Print results....
    I have not tested this code... I didn't read your assignment either, but i hope this gives you a idea.
  4. thread starter macrumors 6502a


    May 5, 2007
    ok i got the code i am only missing one thing..

    how do i make sure that when the user inputs a character that i can print "please enter a integer"
  5. macrumors newbie

    Mar 14, 2008
    Whoh I'm in ECS 15 too
    I have most of the code, i just can't get the whole random.range thing to work, what did you do? Can't figure out the character thing either
  6. thread starter macrumors 6502a


    May 5, 2007
    you have to make an empty list so something like this

    new_list = [] #this makes you a new empty list which you will add on elements to

    so to use the whole random range fx you have to run it thru a for loop.

    so somthing like this...

    for i in range(0, x*):

    x* = name of your input (please enter a integer)
    y* = name of your list

    then just do a sort functions on that list (hint y*.sort()) as that uses the default parameters to list it in numerical order from smallest to largest..

    then just pick the last element of that list and print that out.

    hope i helped.
  7. thread starter macrumors 6502a


    May 5, 2007

    to solve this i implemented exceptions. gday.

Share This Page