From bf36fee25317d0557bc783b6f022ce8b6c4f1684 Mon Sep 17 00:00:00 2001 From: Benjamin Soyka Date: Sat, 22 Sep 2018 18:23:20 -0700 Subject: [PATCH] One file --- data.json | 1 - fortune_helper.py | 13 ------------- fortune_helper.pyc | Bin 608 -> 0 bytes main.py | 47 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 37 insertions(+), 24 deletions(-) delete mode 100644 data.json delete mode 100644 fortune_helper.py delete mode 100644 fortune_helper.pyc diff --git a/data.json b/data.json deleted file mode 100644 index acf7fc1..0000000 --- a/data.json +++ /dev/null @@ -1 +0,0 @@ -[[["Red","Yellow","Green","Blue"],{"1":"You will learn a lot today.","2":"Your shoes will make you happy today.","5":"You are very talented in many ways.","6":"It's better to be alone sometimes."},{"3":"A dream you have will come true.","4":"Now is the time to learn something new.","7":"The man on top of the mountain did not fall there.","8":"Sometimes you just need to lay on the floor."}],[["Red","Yellow","Green","Blue"],{"1":"If you're happy, you're successful.","2":"You will always be surrounded by true friends.","5":"Conquer your fears or they will conquer you.","6":"Rivers need springs."},{"3":"A lifetime of happiness is in store for you.","4":"Everything happens for a reason.","7":"The world may be your oyster, but that doesn't mean you'll get it's pearl.","8":"Do not fear what you don't know."}],[["Red","Yellow","Green","Blue"],{"1":"Beware of bears bearing hugs.","2":"You will fall victim to a freak accident that gets featured on local news.","5":"Your carefully laid plans will be thwarted by a collection of crime-fighting hamsters.","6":"Santa Claus knows what you did. You're relegated to The Naughty List."},{"3":"Your next love interest has a hobby that you detest. Good luck with that.","4":"Before congratulating yourself for jumping 'out of the pan,' you'll soon find yourself 'in the fire.'","7":"Yes, you will fall over in front of the person you have a massive crush on.","8":"There is a pox curse waiting for you in your future."}]] diff --git a/fortune_helper.py b/fortune_helper.py deleted file mode 100644 index c04fb23..0000000 --- a/fortune_helper.py +++ /dev/null @@ -1,13 +0,0 @@ -def represents_int(string): - """Used to check if str can be turned into an int - Args: - string - String to test - Returns: - True - string represents an int - False - string does not represent an int - """ - try: - int(string) - return True - except ValueError: - return False \ No newline at end of file diff --git a/fortune_helper.pyc b/fortune_helper.pyc deleted file mode 100644 index b68e0b5d999e87c15e2125333529c5c33c75dc48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 608 zcmb_YOHKko5UmC@WD;C(f?k zuLnd9U?){w)%EJt>#BdZf|IY0=Y%##;XZ@87FI zBt)-7Z;F%vdvDs*kQ&VcvWKLUk~)nZwk+-wO}CCyErm{IoXmAL(N3&RVxwPJOKA?wA@H@0LzH$9e@mK_^$yY!y)D$d;w zFfG_=Q;6Pn>^2O-20ntn5kaE(#Ltlc!Cjn}d}(cA#qX-(4gKb1A8xH9L`0QyJw*L( zgr!&)EwW@5M;Ap>F1*I*`Z1b-r!?FV&U3cE>3GKZlI`(wB?lnbigaV>@xz>#Le07g eR8zIopi(gOg8pXzlYk~jdy671b3Uy``^i5=tC%qW diff --git a/main.py b/main.py index ad4aa27..fa59692 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,18 @@ -import random, json, fortune_helper -with open("data.json") as file: - fortune_tellers = json.load(file) +import random, json +def represents_int(string): + """Used to check if str can be turned into an int + Args: + string - String to test + Returns: + True - string represents an int + False - string does not represent an int + """ + try: + int(string) + return True + except ValueError: + return False +fortune_tellers = [[["Red","Yellow","Green","Blue"],{"1":"You will learn a lot today.","2":"Your shoes will make you happy today.","5":"You are very talented in many ways.","6":"It's better to be alone sometimes."},{"3":"A dream you have will come true.","4":"Now is the time to learn something new.","7":"The man on top of the mountain did not fall there.","8":"Sometimes you just need to lay on the floor."}],[["Red","Yellow","Green","Blue"],{"1":"If you're happy, you're successful.","2":"You will always be surrounded by true friends.","5":"Conquer your fears or they will conquer you.","6":"Rivers need springs."},{"3":"A lifetime of happiness is in store for you.","4":"Everything happens for a reason.","7":"The world may be your oyster, but that doesn't mean you'll get it's pearl.","8":"Do not fear what you don't know."}],[["Red","Yellow","Green","Blue"],{"1":"Beware of bears bearing hugs.","2":"You will fall victim to a freak accident that gets featured on local news.","5":"Your carefully laid plans will be thwarted by a collection of crime-fighting hamsters.","6":"Santa Claus knows what you did. You're relegated to The Naughty List."},{"3":"Your next love interest has a hobby that you detest. Good luck with that.","4":"Before congratulating yourself for jumping 'out of the pan,' you'll soon find yourself 'in the fire.'","7":"Yes, you will fall over in front of the person you have a massive crush on.","8":"There is a pox curse waiting for you in your future."}]] fortune_teller_number = random.choice(range(len(fortune_tellers))) print("Fortune Teller #{}".format(fortune_teller_number + 1)) fortune_teller = fortune_tellers[fortune_teller_number] @@ -14,8 +26,11 @@ print("") user_input = None while user_input not in pos_0: - user_input = raw_input("Choose an option above, type exactly as shown: ") -if fortune_helper.represents_int(user_input): + try: + user_input = raw_input("Choose an option above, type exactly as shown: ") + except NameError: + user_input = input("Choose an option above, type exactly as shown: ") +if represents_int(user_input): amount_to_move = int(user_input) else: amount_to_move = len(user_input) @@ -34,11 +49,17 @@ user_input = None if pos == 1: while user_input not in pos_1: - user_input = raw_input("Choose an option above, type exactly as shown: ") + try: + user_input = raw_input("Choose an option above, type exactly as shown: ") + except NameError: + user_input = input("Choose an option above, type exactly as shown: ") elif pos == 2: while user_input not in pos_2: - user_input = raw_input("Choose an option above, type exactly as shown: ") -if fortune_helper.represents_int(user_input): + try: + user_input = raw_input("Choose an option above, type exactly as shown: ") + except NameError: + user_input = input("Choose an option above, type exactly as shown: ") +if represents_int(user_input): amount_to_move = int(user_input) else: amount_to_move = len(user_input) @@ -57,11 +78,17 @@ user_input = None if pos == 1: while user_input not in pos_1: - user_input = raw_input("Choose an option above, type exactly as shown: ") + try: + user_input = raw_input("Choose an option above, type exactly as shown: ") + except NameError: + user_input = input("Choose an option above, type exactly as shown: ") print("Your fortune is:") print(pos_1[user_input]) elif pos == 2: while user_input not in pos_2: - user_input = raw_input("Choose an option above, type exactly as shown: ") + try: + user_input = raw_input("Choose an option above, type exactly as shown: ") + except NameError: + user_input = input("Choose an option above, type exactly as shown: ") print("Your fortune is:") print(pos_2[user_input])