Thread: Python help

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

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Python help [Solved]


    Sorta a newbie

    Return a string of the form 'car 1,car 2, car <count>'.

    However, if the count is 6 or more, then use the string 'and <num> more cars' as the last item instead of the actual list of donuts


    This is what I have so far but it does not produce the results I want correctly.

    Code:
    def cars(count):
      if count >= 6:
        count -= 4
        numcars = 'and ' + str(count) + ' more cars'
      else:
        numcarts = 'car ' + str(count)
      return numcars

    I SOLVED IT (The long way, but still figured it out nonetheless :P)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    509
    Rep Power
    33
    In pseudocode ( printing and new line supression ).
    Code:
    if number > 4:
        print donut 1, 2, 3, 4
        print and "remaining" donuts
    else:
        for ctr in range(number)
            print donut ctr+1
    Last edited by dwblas; January 21st, 2013 at 08:58 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0
    I can't use print, I'm suppose to use the return function.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    509
    Rep Power
    33
    Then append to a list or concatenate to a string and return that. Once again
    Code:
    if number > 4:
        print donut 1, 2, 3, 4
        print and "remaining" donuts
    Last edited by dwblas; January 21st, 2013 at 09:02 PM.

IMN logo majestic logo threadwatch logo seochat tools logo