Skip to content

Commit

Permalink
One file
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoyka committed Sep 23, 2018
1 parent fbd12bb commit bf36fee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion data.json

This file was deleted.

13 changes: 0 additions & 13 deletions fortune_helper.py

This file was deleted.

Binary file removed fortune_helper.pyc
Binary file not shown.
47 changes: 37 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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])

0 comments on commit bf36fee

Please sign in to comment.