##### Random fortune
 Random fortune jackthechampion Programmer named Tim Posts: 8 Threads: 7 Joined: Jan 2020 Reputation: Feb-10-2020, 05:25 AM (This post was last modified: Feb-10-2020, 05:25 AM by jackthechampion.) Im making a random fortune teller for my class this is what I have so far can someone fix it for me? Also if you could make it 10 fortunes it needs to be 10 lol ie. ```def MyFortune () : print ("Welcome to my cool fortune teller") print ("This program is guaranteed to predict your future") color = raw_input("Select a color: red, blue, green, or purple: ") if color == "red" or color == "green": number = int(raw_input("Select a number: 1, 2, 5, or 6: ")) if number == 1: print ("You will be very, very rich!") elif number == 2: print ("You will become a jedi master!") elif number == 5: print ("you will live a poor life") elif number == 6: print ("you will become president") else: print ("you must enter 1, 2, 5 or 6") elif color == "blue" or color == "purple": number = int(raw_input("select a number: 3, 4, 7, or 8")) if number == 3: print ("you will die") elif number == 4: print ("you will live a poor life") elif number == 7: print ("you will become a wizard") elif number == 8: print ("you will save the earth") else: print ("you must enter 3, 4, 7, 8") else: print "you must enter a correct color: red, blue, green or purple"``` Reply Posts: 1,780 Threads: 8 Joined: Jun 2018 Reputation: 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. Reply

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020