Day 3 assignment – Apostrophe’s

Today’s exercise is a simple text based adventure. Dr Angela Yu of the Udemy Course 100 Days of Code: The Complete Python Pro Bootcamp for 2022 provided the basic framework. I just need to copy the text, embellish it a bit, and add in the flow control to navigate through the game, resulting in a dead player, or escape the labyrinth. There are no hints on how to navigate the game to win, you need to read the code, or look at the example below.

What is the difference between ‘ and ’ one is an ascii single quote that is used by code to indicate encapsulated text is a string, and the second one is punctuation. It is common to use the single quote. The evil Dr Yu provide the ascii single quote throughout the examples provided. I fortunately have played this game of mismatched single quotes before and converted them first thing.

At this rate I might get through 100 days of code in a couple years, but I’m not in a hurry, and I like the slower pace. I’m also working on blogging. Having something to write everyday is a nice way to practice blog writing.

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

#https://www.draw.io/?lightbox=1&highlight=0000ff&edit=_blank&layers=1&nav=1&title=Treasure%20Island%20Conditional.drawio#Uhttps%3A%2F%2Fdrive.google.com%2Fuc%3Fid%3D1oDe4ehjWZipYRsVfeAx2HyB7LCQ8_Fvi%26export%3Ddownload

#Write your code below this line 👇
user_input = ""
print('You’re at a crossroad. Where do you want to go?' )
while user_input.lower() != "left":
  user_input = input('Type "left" or "right"')
  if (user_input.lower() == "right"):
    print("You hear a painful cry like a little fluffy cute animal calling out for help, you jump into actual and run to the right, but you should look where you are going because you fell into a deep hole and died dead.")

print('You’re come to a lake. There is an island in the middle of the lake.')
while user_input.lower() != "wait":
  user_input = input('Type "wait" to wait for a boat. Type "swim" to swim across.')
  if (user_input.lower() == 'swim'):
    print("You drowned, and now you're dead")
  

print("You arrive at the island unharmed. There is a house with 3 doors. One red, one yellow and one blue.")
while user_input.lower() != 'yellow': 
  user_input = input('Which colour do you choose?')
  if user_input.lower() == 'red':
    print("It’s a room full of fire. Game Over.")
  elif user_input.lower() == "yellow":    
    print("You found the treasure! You Win!")
  elif user_input.lower() == "blue":
    print("You get attacked by an angry trout. Game Over.")
  else:
    print("You chose a door that doesn’t exist. Game Over.")

This is a successful run through looks like:

Welcome to Treasure Island.
Your mission is to find the treasure.
You’re at a crossroad. Where do you want to go?
Type "left" or "right"left
You’re come to a lake. There is an island in the middle of the lake.
Type "wait" to wait for a boat. Type "swim" to swim across.wait
You arrive at the island unharmed. There is a house with 3 doors. One red, one yellow and one blue.
Which colour do you choose?yellow
You found the treasure! You Win!

This is what happens when you enter incorrect directions:

Welcome to Treasure Island.
Your mission is to find the treasure.
You’re at a crossroad. Where do you want to go?
Type "left" or "right" tom
Type "left" or "right" ;et
Type "left" or "right" lft
Type "left" or "right" left
You’re come to a lake. There is an island in the middle of the lake.
Type "wait" to wait for a boat. Type "swim" to swim across. swm
Type "wait" to wait for a boat. Type "swim" to swim across. swam
Type "wait" to wait for a boat. Type "swim" to swim across. sum
Type "wait" to wait for a boat. Type "swim" to swim across. swim
You drowned, and now you're dead
>

Comments are closed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: