Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73902
| X-Received | by 10.58.143.107 with SMTP id sd11mr2278550veb.42.1404392919705; Thu, 03 Jul 2014 06:08:39 -0700 (PDT) |
|---|---|
| X-Received | by 10.140.102.50 with SMTP id v47mr5038qge.19.1404392919687; Thu, 03 Jul 2014 06:08:39 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!enother.net!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!w8no5554272qac.0!news-out.google.com!a8ni6411qaq.1!nntp.google.com!i13no5549980qae.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Thu, 3 Jul 2014 06:08:39 -0700 (PDT) |
| In-Reply-To | <mailman.11457.1404392478.18130.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=198.151.130.240; posting-account=hr1E-woAAADNjPTt4DadGtfyke-Rk1wn |
| NNTP-Posting-Host | 198.151.130.240 |
| References | <7020a5d8-96a9-4fa4-8e69-4c7593dedee3@googlegroups.com> <mailman.11418.1404331330.18130.python-list@python.org> <fd30a5f9-c446-435a-9f0a-74dd2d608c5c@googlegroups.com> <mailman.11457.1404392478.18130.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <51a84c60-f1c0-4a30-94de-e047f1b553bc@googlegroups.com> (permalink) |
| Subject | Re: OOP with MyTime |
| From | kjakupak@gmail.com |
| Injection-Date | Thu, 03 Jul 2014 13:08:39 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Received-Bytes | 2664 |
| X-Received-Body-CRC | 302039274 |
| Xref | csiph.com comp.lang.python:73902 |
Show key headers only | View raw
On Thursday, July 3, 2014 9:01:09 AM UTC-4, Chris Angelico wrote:
>
>
>
> And what happens when you run this code? A NameError, I would expect.
>
> Do you understand how to define and call methods?
>
>
>
> ChrisA
Altered the code. But yes a nameerror came up
class MyTime:
def __init__(self, hrs=0, mins=0, secs=0):
self.hours = hrs
self.minutes = mins
self.seconds = secs
if self.seconds >= 60:
self.minutes += self.seconds // 60
self.seconds = self.seconds % 60
if self.minutes >= 60:
self.hours += self.minutes // 60
self.minutes = self.minutes % 60
if self.hours >= 24:
self.hours = self.hours % 24
def get_sec(self):
return (self.hours * 60 + self.minutes) * 60 + self.seconds
def __str__(self):
return "{:02d}:{:02d}:{:02d}".\
format(self.hours, self.minutes, self.seconds)
def between(self, t1, t2):
return (t1.get_sec() <= (self.get_sec()) and (self.get_sec()) <= (t2.get_sec())
s = MyTime()
t1 = s(9, 59, 59)
print("t1 =", t1)
t2 = s(10, 0, 1)
print("t2 =", t2)
t3 = s(10, 0, 0)
print("t3 =", t3)
print("between(t2, t3, t1) =", s.between(t2, t3, t1))
print("between(t1, t3, t2) =", s.between(t1, t3, t2))
print("between(t3, t1, t2) =", s.between(t3, t1, t2))
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
OOP with MyTime kjakupak@gmail.com - 2014-07-02 12:20 -0700
Re: OOP with MyTime Akira Li <4kir4.1i@gmail.com> - 2014-07-02 23:45 +0400
Re: OOP with MyTime MRAB <python@mrabarnett.plus.com> - 2014-07-02 21:02 +0100
Re: OOP with MyTime kjakupak@gmail.com - 2014-07-03 05:51 -0700
Re: OOP with MyTime Chris Angelico <rosuav@gmail.com> - 2014-07-03 23:01 +1000
Re: OOP with MyTime kjakupak@gmail.com - 2014-07-03 06:08 -0700
Re: OOP with MyTime Chris Angelico <rosuav@gmail.com> - 2014-07-03 23:17 +1000
Re: OOP with MyTime MRAB <python@mrabarnett.plus.com> - 2014-07-03 14:11 +0100
Re: OOP with MyTime kjakupak@gmail.com - 2014-07-03 08:21 -0700
Re: OOP with MyTime Chris Angelico <rosuav@gmail.com> - 2014-07-04 01:35 +1000
Re: OOP with MyTime Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-03 17:23 +0100
csiph-web