Sunday, 8 January 2017

Dead Parrot - Python in Python



# -*- coding: utf-8 -*-
import sys, time
import imp
imp.reload(sys)
if sys.version_info[0] < 3:
    sys.setdefaultencoding('utf-8')

class Parrot:
    def __init__(self, name):
        """
        initialise Parrot object    
        """
        print("Initialising parrot")
        self.latin = "psitticus"
        self.name = name
        self.isalive = True
        self.latin = self.latin + " {n}".format(n=name.lower()+"us")
        
    def dispatch(self):
        print("dispatching parrot")
        self.isalive = False
        
    def printName(self):
        print("This parrot's name is {n}.".format(n=self.name))
        print("Latin: {l}".format(l=self.latin))
        
    def checkAlive(self):
        if self.isalive:
            print("This parrot is healthy.")
        else:
            print("This is an ex-parrot, it has ceased to be.")
            
if __name__ == "__main__":
    if sys.version_info[0] < 3:
        pname = raw_input("What is the parrot's name? ")
    else:
        pname = input("What is the parrot's name? ")
    parrot = Parrot(pname)
    parrot.printName()
    parrot.checkAlive()
    time.sleep(3)
    parrot.dispatch()
    time.sleep(1)
    parrot.checkAlive()

For more EU referendum humour see my previous posts:
Gul Dukat wins galactic presidential election and
Federation Membership referendum.

No comments:

Post a Comment