vendredi 21 septembre 2018

how to end a loop when a random number reaches 0

I'm not great at python and couldn't find a solution that i could understand. I'm trying to get the program to output "random timer has ended" once a random countdown has finished.

import time
from random import randint

RandomTimer = randint(1,10) #picks random number of seconds for countdown
while RandomTimer > 0:
    time.sleep(1)
    RandomTimer - 1  #reduces random number every second until it reaches 0
print("random timer ended")

The code here doesn't work as the countdown never seems to finish, even after 10 seconds. I know there's something i'm doing wrong but can figure it out.




Aucun commentaire:

Enregistrer un commentaire