DEV Community

Frank Promise Edah
Frank Promise Edah

Posted on

python code for a treasure hunt game

Learning python has made me realize the importance of repetition. Especially if one is new to it.

Today, i was able to write a basic code for a treasure hunt game without guidiance

print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.") 



first_choice = input('You\re on a crossroad, where do you want to go? Left or right\n').lower()


if first_choice == 'left':
  second_choice = input('You\ve come to a lake. There is an island in the middle of the lake. Do you wait or swim?\n"').lower()


  if second_choice == 'wait':

    third_choice = input('You have arrived the island unharmed. There is a house with 3 doors. One red, one yellow and one blue. Which colour do you choose?\n').lower()


    if third_choice == 'blue':
      print('Eaten by beasts. Game over')
    elif third_choice == 'red':
      print('burned by fire. Game over')
    elif third_choice == 'yellow':
      print('You win')
    else:
      print('Game over.')


  else:
    print('swallowed by a shark. Game over')

else:
  print('oops! wrong choice. Game over')

Enter fullscreen mode Exit fullscreen mode

Top comments (0)