Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/26/2018 in all areas

  1. Well I finally figured it out I know all through the course Stefan had stressed time and time again about the importance of spaces in Python and I did believe him I just hadn't really learnt the lesson very well until now. So I was determined not to be beaten by this problem with my code, but no matter how many times I looked at my code and compared it to the source code I just couldn't see my fault. Not wanting to move onto the next lesson without fixing my code I decided I'd have to keep checking and re checking until I found my mistake. There it was as plain as day........ SPACING! how could I miss that?? Well I'm not entirely sure how I missed it, but I'm glad i did, I've learnt a very valuable lesson today For comparisons sake heres my newly spaced code: # Python treasure hunt game import random, time def display_game_intro(): print(''' ---->Welcome to the 'Python Treasure Hunt Game' ...the most amazing game ever made! After a long journey, you find yourself in front of two caves. One cave leads to a treasure, the other, a spike filled pit! Being brave, and a little greedy for treasure, you've decided to go for it! ''') def choose_cave(): cave = '' while cave != '1' and cave != '2': print('Which cave do you want to enter? (1 or 2)') cave = input() return cave def enter_cave(chosen_cave): print('\nYou have entered a cave...') time.sleep(1) random_cave = random.randint(1,2) #print("random_cave= " + str(random_cave)) if random_cave == int(chosen_cave): print("---> Lucky you! You found the chest!") else: print("--->You expected to find a chest\n ...and all you found was DEATH!") def main_loop(): ''' The main_loop() function controls the flow of the game by calling functions and using conditionals''' playGameAgain = "yes" while playGameAgain == "yes" or playGameAgain == "y": display_game_intro() chosen_cave = choose_cave() enter_cave(chosen_cave) print("\n\nDo you want to try again? (yes or no)") playGameAgain = input() print("You said: " + playGameAgain) time.sleep(1) if playGameAgain == "yes" or playGameAgain == "y": print("\nLet's try again!") else: print("\nOk, see ya later!") main_loop()
    1 point
×
×
  • Create New...