0
Does anyone know source code of a count down timer...?
any programming language
4 Antworten
+ 10
import time
start=False
while start == False:
    try:
        max=int(input("input amount of seconds to wait: "))
        start=True
    except:
        print("invalid. please input a non decimal number")
count=0
print("countdown started!",max,"seconds left")
while count < max:
    time.sleep(1)
    count+=1
    print(max-count,"seconds left")
print("countdown done")
#youre welcome
+ 1
@Ahri Fox I really hate it when people use a while loop instead of a for loop. in your example you used count=0 and max=int(input()), then said while count<max: print(max-count)
it's much nicer if you would instead of all that just use max=int(input()) for seconds in range(max,-1,-1): print(max)
#i didn't implement all of the code, just the necessary part I'm discussing 
0
class Demo
{
//length to count down in seconds
   	static int time=60;
//Delay to count 1 second at a time
 public static void delay(){
 	try {
    Thread.sleep(1000); }
   catch(InterruptedException ex) {
    Thread.currentThread().interrupt(); }
 	}
//Run Timer
	public static void run(){ 	
 		boolean looper=true;
 		while(looper==true){
        delay();
	  		time--;
  			System.out.println(time);
  			if(time==0){
  				break;
  				}
  			}
  		}
		
	
	public static void main (String[] args) throws java.lang.Exception
	{
		
		run ();
	 	
	}
}
0
@Ahri Fox I really hate it when people use a while loop instead of a for loop. in your example you used count=0 and max=int(input()), then said while count<max: print(max-count)
it's much nicer if you would instead of all that just use max=int(input()) for seconds in range(max,-1,-1): print(max)
#i didn't implement all of the code, just the necessary part I'm discussing 



