# [Tutor] Fwd: Re: Help! (solution)

Wolf Halton wolf.halton at gmail.com
Sat Mar 5 02:09:50 CET 2011

```Put the timing code for one itemt in a while loop and have the variable for
elapsed time incremented by the amount of time the fabricator has to cool
every time the modulus of the loop counter / 127 is 0 AND the count is above
0.

production = 0
time = 127 # seconds
timer = 0
rest = 313
run = input("Enter your run total: ")

while production != run:
timer = timer +  time
if run % production = 0:
timer = timer + rest

print "It took %i  seconds to produce %i items." % (timer, run)

d = 24*60*60
h = 60*60
m = 60
D = timer /  d # how many days
Dsec = timer %  d # seconds left after deducting the days
H = Dsec /  h # how many hours
Hsec = Dsec % h # seconds left after deducting hours.
M = Hsec /  m # how many minutes
Msec  = Hsec % m # seconds left after deducting minutes

print "Production time for %i items: %i Days, %i:%i:%i" % (run, D, H, M,
Msec)

# my 2 cents

---------- Forwarded message ----------
From: "michael scott" <jigenbakuda at yahoo.com>
Date: Mar 4, 2011 7:17 PM
Subject: Re: [Tutor] Help! (solution)
To: <tutor at python.org>

I know that the question has long been answered (and probably due today),
but I
solved it and it was great exercise for me (as I'm not in college at the
moment
and I need assignments like these to gauge my skills). I'll probably build a
gui
for it tomorrow, just so I can practice at that. I wish I had a comp sci
lab...
(T_T) but I digress

But anyways Andrew here is an alternative way to solve the problem (even if
it
is a long and round about method). And to anyone else who is reading beside
Andrew, if something about my code could be better, please tell me, as this
was
just as much a learning experience for me as it is for Andrew. I need
constructive criticism at the moment so I don't develop bad habits.

def production_time():
creation_time = 127
time_till_rest = 18161
items = raw_input("How many items will be produced?\n> ")
item_time = int(items) * creation_time
rest_times = item_time/time_till_rest
print rest_times
if rest_times > 0:
total = item_time + (313 * rest_times) #313 is 5 min and 13 secs in
second form
else: total = item_time
time = sec_to_standard(total)
print "It would take %d days %d hours %d minutes and %d seconds to produce
that many items" %(time[0], time[1], time[2], time[3])

def sec_to_standard(seconds):
day = 86400 #secs
hour = 3600 #secs
mins = 60#seconds
creation_time = 127 #secs
time_till_rest = 18161 #secs
days = 0
hours = 0
minutes = 0
secs = 0
if seconds > day:
while seconds > day:
print "doing days"
seconds = seconds - day
days += 1
if seconds > hour:
while seconds > hour:
print "doing hours"
seconds = seconds - hour
hours += 1
if hours >= 24:
days += 1
hours -= 24
if seconds > mins:
while seconds > mins:
print "doing minutes"
seconds = seconds - mins
minutes += 1
if minutes > 60:
hours += 1
minutes -= 60
secs = seconds
return days, hours, minutes, secs

production_time()

----
What is it about you... that intrigues me so?

________________________________
From: Andrew Bouchot <andy.a.bouchot at gmail.com>
To: tutor at python.org
Sent: Thu, March 3, 2011 4:28:33 PM
Subject: [Tutor] Help!

okay so this is my comp sci lab

Problem: ProductionTime.py It takes exactly 2 minutes and 7 second to
produce an
item. Unfortunately, after 143 items are produced, the fabricator must cool
off
for 5 minutes and 13 seconds before it can continue. Write a program that
will
calculate the amount of time required to manufacture a given number of
items.
Output: Output the amount of time D days HH:MM:SS Sample Input : numItems
=1340
Represents the numbers items to be manufactured Sample Output : 2 days
00:03:17

this is the coding i have written for it!
numitems= int(raw_input("Enter the number of items needed to be
manufactured:"))
seconds=numitems*127
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
print "%d:%02d:%02d" % (h, m, s)
but how would i add the 5 min and 13 seconds after 143 items have been
produced???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110304/917eef9e/attachment.html>
```