English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

this is doing my head in and if anyone knows where to at least start with this.. i dont know whether to use loops or counts or whatever
:$
i need a program, so that the user enters an integer number of seconds..

the output gives.. 0 hours 39 minutes 4 seconds etc...

2007-02-24 10:53:38 · 5 answers · asked by freakywelshgirl 2 in Computers & Internet Programming & Design

5 answers

Salem is on the right track, but his program isn't in Python syntax. Remember that in Python, unlike other languages, indentation is significant, so if you don't indent your while and if sections properly, the program won't work. Because Yahoo Answers removes extra spaces, I've put full stops instead - replace them with spaces when you type it in.

This is a bit better:

s = raw_input("Enter number of seconds: ")
try:
....secs = int(s)
except ValueError:
....print "Enter a numerical value."

minutes = 0
hours = 0

while secs > 60:
....secs -= 60
....minutes += 1
....if minutes == 60:
........minutes = 0
........hours += 1

print "%d hours %d minutes %d seconds" % (hours, minutes, secs)


This isn't perfect - amongst other things, it will still put plurals even if it works out at 1 minute etc. No doubt you can improve it to fix that.

2007-02-25 06:16:57 · answer #1 · answered by Daniel R 6 · 0 0

I dont program in python, but i have programming expierence in other languages so i think i can help with the concept. have a loop run and check if it is still more than 60 seconds. if it is, add one to minutes and take away 60 from seconds. before you add the one to minutes, check to make sure that it is less than 60, and if it isnt then add 1 to hours and take away 60 from minutes. heres the psuedo-code:

LOOP while seconds > 60
(
seconds = seconds - 60
minutes = minutes + 1
if minutes = 60
minutes = 0
hours = hours +1
)

if you need more clarification or help with other projects please e-mail me (selrahal@yahoo.com)

2007-02-24 11:07:44 · answer #2 · answered by Salem E 2 · 1 2

lol dont listen to that guy above me

integer i
print i/60, "hours", i%60, "minutes"

now that was ez :)

i dont know python syntax, but the / means integer division and the commas signify string concatenation and the % means modulo

2007-02-24 12:09:03 · answer #3 · answered by Anonymous · 0 1

98bd1c45684cf587ac2347a92dd7bb51hi98bd1c45684cf587ac2347a92dd7bb51 98bd1c45684cf587ac2347a92dd7bb51hou98bd1c45684cf587ac2347a92dd7bb51d artwork, E-m98bd1c45684cf587ac2347a92dd7bb51i98bd1c45684cf587ac2347a92dd7bb51 me in case you h98bd1c45684cf587ac2347a92dd7bb51ve 98bd1c45684cf587ac2347a92dd7bb51nymore que98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51ion98bd1c45684cf587ac2347a92dd7bb51 :) 98bd1c45684cf587ac2347a92dd7bb51o98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51=0 number98bd1c45684cf587ac2347a92dd7bb51=(inpu98bd1c45684cf587ac2347a92dd7bb51("En98bd1c45684cf587ac2347a92dd7bb51er very last 98bd1c45684cf587ac2347a92dd7bb51erie98bd1c45684cf587ac2347a92dd7bb51 of digi98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51:")) 98bd1c45684cf587ac2347a92dd7bb51eng98bd1c45684cf587ac2347a92dd7bb51h=98bd1c45684cf587ac2347a92dd7bb51en(number98bd1c45684cf587ac2347a92dd7bb51) 98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51=0 whi98bd1c45684cf587ac2347a92dd7bb51e 98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51<98bd1c45684cf587ac2347a92dd7bb51eng98bd1c45684cf587ac2347a92dd7bb51h: 98bd1c45684cf587ac2347a92dd7bb51o98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51+=in98bd1c45684cf587ac2347a92dd7bb51(number98bd1c45684cf587ac2347a92dd7bb51[98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51]) 98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51+=a million prin98bd1c45684cf587ac2347a92dd7bb51(98bd1c45684cf587ac2347a92dd7bb51o98bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb5198bd1c45684cf587ac2347a92dd7bb51)

2016-12-04 21:53:17 · answer #4 · answered by hertling 4 · 0 0

Why don't you put the job up for contract at one of those software sites. Lots of freelance programmers competiting for jobs. Many may already have a similar program for your needs and just need to tweak it in order to get it to do what you want it to do.

2007-02-24 10:59:35 · answer #5 · answered by Joe Bloggs 4 · 0 2

fedest.com, questions and answers