Feb-10-2020, 07:52 AM
Just to give an idea: maybe use dictionary?
>>> fortunes = {'red': {1: 'be happy', 2: "don't worry"}, ... 'blue': {3: 'monday', 4: 'tuesday'}} >>> color = 'red' >>> num = 2 >>> fortunes[color][num] # works like charm "don't worry" >>> fortunes['purple'][1] # but throws an error if there is no such a key /.../ KeyError: 'purple'One can use try...except to handle non-existing keys (alternatively perform input validation):
try: fortune = fortunes[color][num] # do something with fortune except KeyError: # handle situation of incorrect input
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.