So
donuts(3) returns 'donut 1,donut 2,donut 3'
donuts(4) returns 'donut 1,donut 2,donut 3,donut 4'
donuts(10) returns 'donut 1,donut 2,donut 3,donut 4,and 6 more donuts'
donuts(20) also returns 'donut 1,donut 2,donut 3,donut 4,and 16 more donuts'
Python functions: range(), str()
This is what I have so far but it does not produce the results I want correctly.
def donuts(count):
if count >= 5:
count -= 4
numDonuts = 'and ' + str(count) + ' more donuts'
else:
numDonuts = 'donut ' + str(count)
return numDonuts
I get:
'donut 1'
'donut 3'
'donut 4'
'and 6 more donuts'
'and 95 more donuts'
but I need this:
output
‘donut 1’
‘donut 1,donut 2,donut 3’
‘donut 1,donut 2,donut 3,donut 4’
‘donut 1,donut 2,donut 3,donut 4 and 6 more donuts’
‘donut 1,donut 2,donut 3,donut 4 and 95 more donuts’
I tried to implement the range function but I still can't get it to say donut1,donut2,donut3 in that order.

New Topic/Question
Reply



MultiQuote






|