DEV Community

Cover image for Day 02 of My AI & Data Mastery Journey: From Python to Generative AI
Nitin-bhatt46
Nitin-bhatt46

Posted on

Day 02 of My AI & Data Mastery Journey: From Python to Generative AI

TODAY’S PROJECT

Project:-
Treasure Island Game

  1. Display "Welcome to Treasure Island."
  2. Display "Your mission is to find the treasure."
  3. Prompt player: Type "left" or "right" → store response in variable a
  4. IF a equals "left":
  5. Prompt player: You’ve come to a lake... Type "swim" to swim across or "wait" to wait for a boat → store response in b (convert to lowercase)
  6. IF b equals "swim":
  7. Prompt player: You’ve reached the door... choose the color "Blue", "Red" or "Green" → store in c (lowercase)
  8. IF c equals "blue": DISPLAY "Eaten by beasts GAME OVER"
  9. ELSE IF c equals "red": DISPLAY "Burned by the fire GAME OVER"
  10. ELSE IF c equals "green": DISPLAY "YOU WIN!"
  11. ELSE: DISPLAY "GAME OVER"
  12. ELSE: DISPLAY "Game Over"
  13. ELSE: DISPLAY "Fall into a hole Game Over"

Now it’s time for some hands-on practice.
👉 Are you ready for today’s learning challenge?”

Creation 1 — Treasure Island v2 (enhanced rules & scoring)

Build a new version of the Treasure Island game that:
Greets the player and asks for their name (use it in messages).
Keeps game choices case-insensitive.
Adds a simple scoring rule:
+10 points for choosing "left".
+20 points for "wait" (boat).
+30 points for choosing the correct door ("green").
-10 penalty for any wrong terminal choice (game over).
After the game ends (win or lose) print:
Player name, final score, and a short message:
If score ≥ 50 → "Legendary treasure hunter!"
If 20 ≤ score < 50 → "Nice job — keep practicing."
Else → "Better luck next time."
Make sure invalid inputs are handled (show "Invalid choice — game over." and apply -10 penalty).
Goal: combine input, conditional flow, string handling, simple arithmetic (score), and function usage.

Creation 2 — Tip Splitter with Username & Validation

Create a tip-splitting program that combines your username generator concept:

Ask for the user’s first name and birth year → generate username as firstName_birthYear (use underscore).
Ask for bill amount, tip %, and number of people.
Validate inputs:
Bill and tip must be positive numbers.
Number of people must be integer ≥ 1.
If invalid, print a helpful message and stop.
Calculate each person’s share: (bill + tip) / people. Tip is bill * tip% / 100.
Print:
Username
Total bill with tip
Amount each person pays, formatted to 2 decimal places
Bonus: if birth year implies age < 18, print a warning "Underage user - tip suggestion disabled" and force tip to 0.
Goal: combine input validation, arithmetic, string formatting, and reuse your username idea.

Debugging Questions

Debug Question 1:-

Broken Treasure Flow (logic + case errors)
Fix the bugs (syntax/logic/case-sensitivity) in this snippet so the game behaves correctly:

choice = input("Left or Right? ")
if choice = "left" or "Left":
action = input("Swim or Wait? ")
if action.lower == "wait":
door = input("Pick color: Red/Green/Blue ")
if door == "green":
print("You win")
elif door == "red":
print("Burned by fire")
else:
print("Eaten")
else:
print("Game Over")
else:
print("Game Over")
What to fix: assignment/comparison error, case handling, wrong method usage, and ensure only "green" wins while other colors give proper messages. Also make or condition correct.

Debugging 2 — Tip Calculator Type & Division Bug

This tip calculator has multiple issues. Fix them and make it robust:

bill = input("Total bill: ")
percent = input("Tip %: ")
people = input("Split among: ")
total = bill + (bill * percent / 100)
each = total / people
print("Each pays: " + each)

Bugs to fix:
Type conversions (strings → numeric)
Use floats for bill/tip
Handle people as integer and guard against people == 0
Format the printed result to 2 decimal places and include a friendly message.

🎯 You’ve completed AI & Data Mastery Journey – 02

Top comments (0)