Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:15:23+00:00 2026-06-08T07:15:23+00:00

The program prints Expired the first time. I am expecting the code to print

  • 0

The program prints Expired the first time. I am expecting the code to print “not expired” for atleast 4 times before printing expired. Can someone please explain the reason and help me correct the code. Thank you

import time
TIMEOUT =  5

class Timer ():
    def __init__(self):
        self.timeout = time.time()+TIMEOUT
    def isExpired ():
        return time.time() > self.timeout

timing = Timer()

def main():
    while 1:
        if timing.isExpired:
            print "Expired"
            return
        else:
            print "Not expired"
            print "sleeping for 1 second"
            time.sleep(1)

if __name__== "__main__":
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:15:25+00:00Added an answer on June 8, 2026 at 7:15 am

    You have several problems:

    1. You did not give your isExpired method a self argument. Define it as def isExpired(self):.

    2. You are creating a new Timer instance on each loop iteration. Move the timing = Timer() outside the while loop.

    3. timing.isExpired is a reference to the method object iself (which is always true in a boolean context). You need to do timing.isExpired() to actually call it.

    These are all basic Python issues that have nothing to do with Timer. Read the Python tutorial to learn how to use classes and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which prints a multi-page document. The first page is pre-printed
Is it possible to make a Java program that prints its source code to
In the following code, am executing a java program Newsworthy_CA. The program prints the
For some reason when I run the following code the program prints out JDN4
Below program prints the Currency symbol given the ISO 4217 currency code. import java.util.*;
The program below prints the following data: Wed,Jun,13,10:37:34,2012,759,41,0,30,10,0,0,1 Wed,Jun,13,10:38:34,2012,767,33,0,25,6,0,0,2 Wed,Jun,13,10:39:34,2012,758,42,0,32,10,0,0,0 Wed,Jun,13,10:40:35,2012,758,42,0,29,11,0,0,2 Wed,Jun,13,10:41:35,2012,761,39,0,34,5,0,0,0 Wed,Jun,13,10:42:35,2012,769,31,0,22,6,0,0,3 Wed,Jun,13,10:43:35,2012,754,46,0,29,17,0,0,0
The program below prints: my name is:null my name is:null Someclass static init AFAIK
I need to write a program that prints 0.(03) for input 1 and 33.
I have a command line program that prints out a report such as: I
I am writing a program that uses prints a hex dump of its input.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.