Q&A for How to Make a Countdown Program in Python

Return to Full Article

Search
Add New Question
  • Question
    How do I get it to print at each second rather than having it all print at once?
    Community Answer
    Use the time.sleep(x) function. It allows for the program to pause for x seconds. After every print statement, insert time.sleep(1).
  • Question
    How do I make the font larger in Python on a Mac?
    Community Answer
    In the Python shell, click Options, Configure, Idle. From there, you can change the font size.
  • Question
    Why have the 'time' module if it is never used?
    Community Answer
    If you write a program for, say, a robot and have the servo controls in milliseconds, then it will use the time module to send the electrical signal for the right amount of time.
  • Question
    I keep getting the following error: "expected an indented block." What have I done wrong?
    Community Answer
    You need to press the "Tab" key to indent, so if you were doing an "if" loop. you would do: if a = b: print("Indentation is the space before print")
  • Question
    I want to print the time on the video screen. What should I do?
    Community Answer
    I assume that you mean the Python Turtle Graphics window. If I`m correct, you should use the function "write()" instead of "print()". Then you would have to add "clear()" because "write()" does not change the lines automatically. Otherwise you could move the position of your Turtle. To use the function "write()", you also have to add "from turtle import *".
  • Question
    I'm using LiClipse and when loading the code, it loads, but nothing happens. Indentation is fine and the only thing I have changed is changing the variable n to a.
    Community Answer
    Check for syntax errors, most commonly a semi-colon at the end of all required phases, and make sure that your OS, drivers, and Python are all latest update. It may also be helpful to check the firewall and see if it's blocking the interface.
  • Question
    How can I stop or abort the countdown?
    Community Answer
    By using the "break" keyword. For example, if you wanted to initiate a countdown but wanted to stop it halfway through, you could try something like this: i = 10 while i < 10: print(i) i -= 1 if i == 5 break print("done")
  • Question
    How do I create a timer that produces a random number after a set amount of time in Python?
    Community Answer
    First import random. You can then add this line after the code: random.choice(1,2,3,4,5,6,7,8,9).
  • Question
    How do I run a background timer in a quiz?
    Invisible One
    Community Answer
    This is difficult to do in Python. You should use threading to accomplish this: def laughing: while True: print("Haha") thread1 = threading(laughing) thread1.start()
  • Question
    How can I learn Python in 30 days?
    BJW1661
    Community Answer
    There is no set amount of time to learn Python. However, it can be accomplished in that time. Don’t rush, otherwise you will risk giving up out of frustration. There are no shortcuts, you just need to take your time, learn by doing and you’ll get there.
  • Question
    If i don't want the timer to appear every x second, how do I write the code if I want the user to type the command (eg: !timer) then it ask "How many seconds to count down? Enter an integer:" ?
    Simeon Watson
    Community Answer
    You'd write it as: import time time = int(input("How many seconds to countdown? Enter an integer: ")) time.sleep(time) print("Countdown for", time, "seconds is over!")
Ask a Question

      Return to Full Article