The Noobs of Python: Ep.4.0 - What's your Function / Define your Function

You could, I suppose, argue that the if/elifs are a bit cumbersome to read (and probably type, too).
I'd go for that because I'm a lazy twerp.
I'd probably write something more along the lines of this to save myself and my keyboard the effort.

from random import choice

def Quotes(Classic_Quote):
        return {"a":"Luke I am your Father !!!",
                "b":"When nine hundred years old you reach, look as good you will not",
                "c":"Truly wonderful, the mind of a child is.",
                "d":"That is why you fail.",
                "e":"A Jedi uses the Force for knowledge and defense, never for attack.",
                "f":"Adventure. Excitement. A Jedi craves not these things.",
                "g":"Judge me by my size, do you?",
                "h":"Fear is the path to the dark side…fear leads to anger…anger leads to hate…hate leads to suffering",
                "i":"Wars not make one great.",
                "j":"Luminous beings are we…not this crude matter.",
                "e":"Do. Or do not. There is no try.",
                "e":"Never tell me the odds!"}.get(Classic_Quote)

ran = choice('abcdefghijkl')
txt = Quotes(ran)
print(txt)

Dictionaries are rad. That function will also return None alike in the original if the quote letter/whatever isn't found (if the key given to the .get() method isn't found in the dictionary, it returns None).

2 Likes