Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 21st, 2013, 08:39 PM
psk102000 psk102000 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 psk102000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 26 sec
Reputation 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)

Reply With Quote
  #2  
Old January 21st, 2013, 08:49 PM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 55 m 26 sec
Reputation Power: 7
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.

Reply With Quote
  #3  
Old January 21st, 2013, 08:54 PM
psk102000 psk102000 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 psk102000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 27 m 26 sec
Reputation Power: 0
I can't use print, I'm suppose to use the return function.

Reply With Quote
  #4  
Old January 21st, 2013, 09:00 PM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 294 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 55 m 26 sec
Reputation Power: 7
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap