From 671a528b7f16f4b98a9134520aba7f0a31918d5b Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Fri, 3 Jul 2015 22:37:20 +0200 Subject: [PATCH] No KeyboardInterrupt error --- redcode.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) mode change 100644 => 100755 redcode.py diff --git a/redcode.py b/redcode.py old mode 100644 new mode 100755 index ee54050..503c7c3 --- a/redcode.py +++ b/redcode.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from random import randint, choice from sys import stdout from time import sleep @@ -7,13 +8,17 @@ GREEN='\033[32m' YELLOW='\033[33m' BLUE='\033[34m' WHITE='\033[37m' +RESET='\033[0m' colors = [ RED, GREEN, GREEN ] -while True: - if randint(0,99) < 30: - stdout.write(choice(colors)) - stdout.write('%X' % randint(0,15)) - stdout.flush() - sleep(0.005) - +try: + while True: + if randint(0,99) < 30: + stdout.write(choice(colors)) + stdout.write('%X' % randint(0,15)) + stdout.flush() + sleep(0.005) +except KeyboardInterrupt: + stdout.write(RESET+"\n") + stdout.flush()