Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SireeshaNarra Decoding Recipe Implementation for Challenge #3 #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions decode_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# decode_recipe.py

# Define the encoding dictionary
ENCODING = {
'h': 'b', 'g': 'u', 'i': 't', 'k': 'e', 'f': 'r',
# Add all other mappings here
}

def decode_string(encoded_string):
"""Decode a single encoded string using the ENCODING dictionary."""
decoded_string = ''.join(ENCODING.get(char, char) for char in encoded_string)
return decoded_string

def decode_ingredient(encoded_line):
"""Decode a line from the recipe into an Ingredient object."""
print(f"Decoding line: {encoded_line}")
# Split the line into amount and description
amount, encoded_desc = encoded_line.split('#')
amount = decode_amount(amount) # Implement decode_amount function
description = decode_string(encoded_desc)
return Ingredient(amount, description)

def decode_amount(encoded_amount):
"""Decode the amount part of the ingredient (e.g., '8 vgl' to '1 cup')."""
# Implement this function based on your requirements
return '1 cup'

def decode_recipe(file_path):
"""Read and decode the entire recipe from a file."""
print(f"Decoding recipe from file: {file_path}")
with open(file_path, 'r') as file:
lines = file.readlines()

decoded_lines = []
for line in lines:
decoded_lines.append(decode_ingredient(line.strip()))

with open('decoded_recipe.txt', 'w') as file:
for ingredient in decoded_lines:
file.write(f"{ingredient.amount} {ingredient.description}\n")

class Ingredient:
def __init__(self, amount, description):
self.amount = amount
self.description = description

# For testing purposes
if __name__ == "__main__":
print("Script is running")
decode_recipe('secret_recipe.txt')
2 changes: 2 additions & 0 deletions decoded_recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 cup two
1 cup 1
1 change: 1 addition & 0 deletions funfacts/Spring2022/sireeshanarra/funfacts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I can solve a Rubik's Cube in under two minutes.
2 changes: 2 additions & 0 deletions secret_recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
8 vgl#two
4 cups#1