Program with Output

# Uses python function "print" to ouput text in the quotes
print("hello world")
hello world

Program with Input –> Output

# Asks user what the name is
print("What is your name?")
# Python takes input from user and stores it into the variable "name"
name = input()
# Uses name variable to print with name inserted earlier

print(f"Your name is {name}")
What is your name?
Your name is saathvik

Program with a List

# Uses a list. A list has brackets "[]"
animals = ["cheeta", "elephant", "dog", "cat", "chicken"]
# Prints the list
print(animals)
['cheeta', 'elephant', 'dog', 'cat', 'chicken']

Program with a Dictionary

# Uses a dictionary with a key and value
info = {
    "first_name" : "saathvik",
    "last_name" : "Gampa",
    "age" : "fifteen",
    "school" : "DNHS"
}
# Prints a dictionary
print(info)
{'first_name': 'saathvik', 'last_name': 'Gampa', 'age': 'fifteen', 'school': 'DNHS'}

Program with an iteration

# Uses a dictionary to store keys and values
info = {
    "first_name" : "saathvik",
    "last_name" : "Gampa",
    "age" : "fifteen",
    "school" : "DNHS"
}

## For Loop to iterate through keys and values of the dictionary "info"

for i in info:
    number = str(number)
    value = info[i]
    print(value)

saathvik
Gampa
fifteen
DNHS

Program with a mathematical function

print("How much points did you get on your test?")
score = input()
print("How many points was the test out of?")
points_out_of = input()
final_score = int(score) / int(points_out_of)
final_score = final_score * 100
print(f"Your percentage is {final_score}% ")
How much points did you get on your test?
How many points was the test out of?
Your percentage is 75.0% 

Final Project Implementing all of the above!

Recipe book manager


# Define the Recipe class to store details about a recipe
class Recipe:
    # Constructor to initialize a Recipe object
    def __init__(self, name, ingredients, instructions):
        self.name = name
        self.ingredients = ingredients
        self.instructions = instructions

    # Method to display the recipe details
    def display(self):
        print(f"Recipe Name: {self.name}")
        print("\nIngredients:")
        for ingredient in self.ingredients:
            print(f"- {ingredient}")
        print("\nInstructions:")
        for instruction in self.instructions:
            print(f"- {instruction}")

# Function to search for a recipe by name from a list of recipes
def find_recipe(name, recipes):
    for recipe in recipes:
        if recipe.name.lower() == name.lower():
            return recipe
    return None

# Function to delete a recipe by name from a list of recipes
def delete_recipe(name, recipes):
    for index, recipe in enumerate(recipes):
        if recipe.name.lower() == name.lower():
            del recipes[index]
            return True
    return False

# List to store all the recipes
recipes = []

# Main loop for the Recipe Book Manager
while True:
    print("\nWelcome to the Recipe Book Manager")
    print("Select your action")
    print("A: Add a recipe \nB. View a Recipe \nC. Delete a Recipe \nD. Exit")

    choice = input("Your Choice: ").upper()

    # Add a new recipe
    if choice == "A":
        recipe_name = input("Enter the name of the recipe: ")

        ingredients = []
        while True:
            ingredient = input("Add an ingredient (or type 'done' to finish): ")
            if ingredient.lower() == 'done':
                break
            ingredients.append(ingredient)

        instructions = []
        while True:
            instruction = input("Enter the process/instructions for the recipe (Type 'done' to finish): ")
            if instruction.lower() == "done":
                break
            instructions.append(instruction)

        new_recipe = Recipe(recipe_name, ingredients, instructions)
        recipes.append(new_recipe)
        print("Recipe added successfully!")
        new_recipe.display()

    # View a specific recipe
    elif choice == "B":
        recipe_name = input("Enter the name of the recipe you want to view: ")
        recipe = find_recipe(recipe_name, recipes)
        if recipe:
            recipe.display()
        else:
            print("Recipe not found!")

    # Edit or Delete a specific recipe
    elif choice == "C":
        action = input("Would you like to Edit (E) or Delete (D) a recipe? ").upper()

        if action == "D":
            recipe_name = input("Enter the name of the recipe you want to delete: ")
            if delete_recipe(recipe_name, recipes):
                print("Recipe deleted successfully!")
            else:
                print("Recipe not found!")

    # Exit the Recipe Book Manager
    elif choice == "D":
        print("Goodbye!")
        break

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  A
Enter the name of the recipe:  apple pie
Add an ingredient (or type 'done' to finish):  apples
Add an ingredient (or type 'done' to finish):  oven
Add an ingredient (or type 'done' to finish):  dough
Add an ingredient (or type 'done' to finish):  done
Enter the process/instructions for the recipe (Type 'done' to finish):  1. bake oven
Enter the process/instructions for the recipe (Type 'done' to finish):  2nd eat
Enter the process/instructions for the recipe (Type 'done' to finish):  done


Recipe added successfully!
Recipe Name: apple pie

Ingredients:
- apples
- oven
- dough

Instructions:
- 1. bake oven
- 2nd eat

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  b
Enter the name of the recipe you want to view:  apple pie


Recipe Name: apple pie

Ingredients:
- apples
- oven
- dough

Instructions:
- 1. bake oven
- 2nd eat

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  c
Would you like to Edit (E) or Delete (D) a recipe?  apple pie



Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  b
Enter the name of the recipe you want to view:  apple pie


Recipe Name: apple pie

Ingredients:
- apples
- oven
- dough

Instructions:
- 1. bake oven
- 2nd eat

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  c
Would you like to Edit (E) or Delete (D) a recipe?  apple pie



Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  c
Would you like to Edit (E) or Delete (D) a recipe?  d
Enter the name of the recipe you want to delete:  apple pie


Recipe deleted successfully!

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  b
Enter the name of the recipe you want to view:  apple pie


Recipe not found!

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  d


Goodbye!


Recipe added successfully!
Recipe Name: apple

Ingredients:
- idk
- idk
- idk

Instructions:
- cap
- cap

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  b
Enter the name of the recipe you want to view:  apple


Recipe Name: apple

Ingredients:
- idk
- idk
- idk

Instructions:
- cap
- cap

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  c
Would you like to Edit (E) or Delete (D) a recipe?  D
Enter the name of the recipe you want to delete:  apple


Recipe deleted successfully!

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit


Your Choice:  b
Enter the name of the recipe you want to view:  apple


Recipe not found!

Welcome to the Recipe Book Manager
Select your action
A: Add a recipe 
B. View a Recipe 
C. Delete a Recipe 
D. Exit