473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

asking an user to enter a time

i am asking an user to enter time, then add the time together to get a new times
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     origTime = raw_input("Enter clock time (hh:mm): ")
  3.     hrsAdd = input("Enter hours to add: ")
  4.     hhmm = origTime.split (':')
  5.     hh = int(hhmm[0])
  6.     mm = hhmm[1]
  7.     hourSum = "origTime + hrsAdd"
  8.     print "New time: %d:%s" % (hourSum, mm)
Apr 4 '07 #1
8 1598
bartonc
6,596 Expert 4TB
i am asking an user to enter time, then add the time together to get a new times
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     origTime = raw_input("Enter clock time (hh:mm): ")
  3.     hrsAdd = input("Enter hours to add: ")
  4.     hhmm = origTime.split (':')
  5.     hh = int(hhmm[0])
  6.     mm = hhmm[1]
  7.     hourSum = "origTime + hrsAdd"
  8.     print "New time: %d:%s" % (hourSum, mm)
Very nice. Nicer with CODE tags, though.
Apr 5 '07 #2
ilikepython
844 Expert 512MB
i am asking an user to enter time, then add the time together to get a new times
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     origTime = raw_input("Enter clock time (hh:mm): ")
  3.     hrsAdd = input("Enter hours to add: ")
  4.     hhmm = origTime.split (':')
  5.     hh = int(hhmm[0])
  6.     mm = hhmm[1]
  7.     hourSum = "origTime + hrsAdd"
  8.     print "New time: %d:%s" % (hourSum, mm)

Why are you using quotes around the "origTime + hrsAdd". Are you having any problems?
Apr 5 '07 #3
is not working,
i could only the hours but is not adding together and get the result
Apr 5 '07 #4
ilikepython
844 Expert 512MB
is not working,
i could only the hours but is not adding together and get the result
First you need to remove the quotes around the hourSum line. You wrote origTime + hrsAdd. That doesn't work because the variable "origTime" is a string. You want to add hours to "origTime", am I correct?
If so I believe you have to add "hrsAdd" to "hh". Then you would get:
Expand|Select|Wrap|Line Numbers
  1. hourSum = hh + hrsAdd
  2.  
Does that help?
Apr 5 '07 #5
bartonc
6,596 Expert 4TB
i am asking an user to enter time, then add the time together to get a new times
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     origTime = raw_input("Enter clock time (hh:mm): ")
  3.     hrsAdd = input("Enter hours to add: ")
  4.     hhmm = origTime.split (':')
  5.     hh = int(hhmm[0])
  6.     mm = hhmm[1]
  7.     hourSum = "origTime + hrsAdd"
  8.     print "New time: %d:%s" % (hourSum, mm)
My friend, ilikepython is correct. You can copy and paste this correction into your editor:
Expand|Select|Wrap|Line Numbers
  1. def main():
  2.     origTime = raw_input("Enter clock time (hh:mm): ")
  3.     hrsAdd = input("Enter hours to add: ")
  4.     hhmm = origTime.split (':')
  5.     hh = int(hhmm[0])
  6.     mm = hhmm[1]
  7.     hourSum = origTime + hrsAdd
  8.     print "New time: %d:%s" % (hourSum, mm)
Apr 5 '07 #6
bvdet
2,851 Expert Mod 2GB
is not working,
i could only the hours but is not adding together and get the result
To convert a time string in this format "hh:mm:ss" to a value:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "12:45:45"
  2. >>> dd = dict(zip([1, 60, 360], [float(i) for i in s.split(':')]))
  3. >>> sum([f/v for v, f in dd.items()])
  4. 12.875
  5. >>> 
So:
Expand|Select|Wrap|Line Numbers
  1. def hms(s):
  2.     dd = dict(zip([1, 60, 360], [float(i) for i in s.split(':')]))
  3.     return sum([f/v for v, f in dd.items()])
  4.  
  5. def main():
  6.     origTime = raw_input("Enter clock time (hh:mm): ")
  7.     hrsAdd = raw_input("Enter hours to add (hh:mm): ")
  8.     return hms(origTime) + hms(hrsAdd)
  9.  
  10. print main()
Apr 5 '07 #7
ghostdog74
511 Expert 256MB
there's a similar situation in this recent thread . you can get some ideas there.
Apr 5 '07 #8
thank your all those posts.
Apr 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: hokiegal99 | last post by:
I don't understand how to use a loop to keep track of user input. Could someone show me how to do what the program below does with a loop? Thnaks! ---------------------------- #Write a...
1
by: tom | last post by:
Hey All, I have a subform that shows records in datasheet view, all sorted nicely. When I right-click on any column and choose "Sort Ascending", Access pops up an "Enter Parameter" box for a...
2
by: Marius Kaizerman | last post by:
Hi, I have a report that is a based on a query. One of the fields in the query is "time of sale", which is a date field that holds the sales dates (day,month,year). I want to use that field as...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
4
by: anand | last post by:
Hi, I have an Access 2000 database, which contains some native tables, and some linked tables which belong to an ORACLE database, through ODBC. Using VB.NET, I am trying to fetch some data by...
18
by: Andrew Gentile | last post by:
Hello, I would like to find a way of using scanf() and the Enter key to have user-controlled program flow. Currently, I have a couple of lines in my program which serves as a pause in the...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
5
by: no1zson | last post by:
I have been reading through many of the array questions and cannot find one that addresses my issue. Maybe someone can help me out. Same story, I am learning Java and have just written a CD...
5
by: vovan | last post by:
I have set of controls (Textboxes, checkboxes etc) along with the Grid on Windows Form. I use BindingSource to populate both Grid and the set of Controls. User selects the record in the grid and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.