0% found this document useful (0 votes)
31 views

Introduction To Coding & Computational Thinking Exercises

Uploaded by

Isiaka Idris
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Introduction To Coding & Computational Thinking Exercises

Uploaded by

Isiaka Idris
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Introduction to Coding & Computational Thinking

Sample Exercise: Planning a Group Trip Plan: From Office Apartments


(Ikeja, Lagos) to Yankari Game Reserve, Bauchi
Objective: Plan a 4-day, 3-night group trip with a total budget of ₦1,200,000, including
transportation, accommodation, itinerary, and meals.

Solution Steps:
Step 1: Decompose the Trip

1. Transportation: Decide on the best method to travel to Bauchi State, either by road
or air, based on cost and convenience.
2. Accommodation: Find suitable lodging near Yankari Game Reserve that can
accommodate the group.
3. Itinerary: Plan activities at Yankari Game Reserve, considering daily schedules,
activities available at the park, and time for meals.
4. Meals: Budget for three meals daily for each participant, with emphasis on
affordable yet enjoyable options.

Step 2: Recognize Patterns

1. Transportation Patterns:
○ Flight costs fluctuate based on booking time; booking in advance reduces
costs.
○ Road travel costs can increase with fuel price hikes, and car rental charges
vary by vehicle type and mileage.
2. Accommodation Patterns:
○ Lodges around Yankari Game Reserve offer group discounts if rooms are
booked in bulk.
○ Accommodation costs may also vary depending on the day of the week, with
weekends generally pricier.
3. Itinerary Patterns:
○ Guided tours and safari activities have specific times; planning around these
schedules saves time and ensures participation.
○ Some activities (like night safari tours) may cost extra, so budgeting for
these in advance is essential.

Step 3: Abstract Major Steps

Focus on key aspects:

1. Choose Transportation: Compare flights vs. car rental costs, accounting for the
budget and time constraints.
2. Book Accommodation: Find group lodging, focusing on budget and proximity to
Yankari Game Reserve.
3. Plan Daily Itinerary: Include a safari tour, spring visit, and other available
activities.
4. Set a Meal Budget: Decide on daily meal expenses to keep the total trip cost within
budget.

Step 4: Design an Algorithm for Trip Planning

1. Initialize total budget: ₦1,200,000


2. Calculate maximum spend per category:
○ Transport = ₦400,000
○ Accommodation = ₦500,000
○ Itinerary = ₦200,000
○ Meals = ₦100,000
3. Select transport option within ₦400,000:
○ Identify transport options, such as group rental buses, flights, or trains.
○ Compare costs:
■ For flights, calculate the round-trip cost per person and ensure it’s
within budget.
■ For road transport (bus or rental), estimate fuel and rental fees.
○ If multiple options are under ₦400,000, select the cheapest.
○ Allocate final selected transport cost.
4. Search for accommodation under ₦500,000:
○ Explore available hotels, lodges, or guest houses near Yankari Game Reserve.
○ Prefer group rooms or rentals for cost efficiency.
○ Calculate nightly rate per person, ensuring total stay cost is within the
accommodation budget.
○ Reserve the accommodation that offers the best amenities within the budget.
5. Plan daily itinerary within ₦200,000:
○ List available activities at Yankari Game Reserve (e.g., wildlife tours, hot
springs).
○ Choose one main activity per day that costs less than ₦50,000.
○ Sum up the activity costs to ensure they don’t exceed ₦200,000.
○ Allocate itinerary budget to each day’s activity.
6. Allocate daily meal budget of ₦2,000 per person:
○ Calculate total meal cost: ₦2,000 x total number of people x number of days.
○ If the total exceeds ₦100,000, adjust meal plans (e.g., include self-prepared
meals or budget dining).
○ Ensure the final meal allocation stays within the meals budget.
7. Adjust any category to remain within the total budget:
○ If any category exceeds its allocated budget, adjust by:
■ Choosing a lower-cost option in transport or accommodation.
■ Limiting itinerary activities or reducing the meal budget per person.
○ Re-validate that the total remains under ₦1,200,000 before finalizing plans.

Final Plan:

1. Transportation:
○ Option: Round-trip car rental for flexibility and cost-effectiveness.
○ Cost: ₦400,000 for a 7-seater SUV with fuel and tolls included.
2. Accommodation:
○ Yankari Tourist Camp: Group lodge with rooms available at ₦50,000/night
per room for 3 rooms, totaling ₦450,000.
○ Total for 3 nights: ₦450,000
3. Itinerary:
○ Day 1: Arrival and settle into accommodations
○ Day 2: Morning - Safari tour (₦50,000), Afternoon - Visit to Wikki Warm
Springs (₦30,000)
○ Day 3: Morning - Guided hike (₦20,000), Afternoon - Game viewing and
nature walk
○ Day 4: Departure
○ Total Itinerary Cost: ₦100,000
4. Meals:
○ Budget: ₦25,000/day for 6 people
○ Total: ₦100,000 for the trip

Final Budget Breakdown


Category Description Cost

Transportation Car rental with fuel and tolls ₦400,000

Accommodation 3 rooms for 3 nights ₦450,000

Itinerary Safari, Wikki Warm Springs, hike ₦100,000

Meals Daily meal budget ₦100,000

Total Cost ₦1,050,000

Hands-On Exercise: Planning a Group Trip Using Computational


Thinking
Objective: Apply computational thinking techniques to create a practical and budget-
friendly group trip plan.

Problem Statement:
Plan a group trip that meets the following requirements:

1. 4 days, 3 nights stay


2. Group of 6 people
3. Total budget: ₦2,000,000
4. Travel to Ikogosi Warm Springs in Ekiti State
5. Includes transportation, accommodation, daily itinerary, and meals

Solution Steps:
Step 1: Decompose the Trip

1. Break down the trip into major planning categories:


○ Transportation: How will the group travel to the destination?
○ Accommodation: Where will they stay?
○ Itinerary: What activities will they do each day?
○ Meals: How much should they budget for meals?
2. Create a checklist under each category:
○ Transportation: vehicle rental, fuel, tickets (if applicable)
○ Accommodation: lodging cost per night, group room availability
○ Itinerary: planned activities, entry fees, estimated time for each activity
○ Meals: number of meals per day, estimated cost per person

Step 2: Recognize Patterns

1. Research travel costs and identify common patterns in prices:


○ Notice if prices vary based on day of the week or time of booking.
○ Identify discounts for group bookings or bulk meal orders.
2. Example Patterns to Consider:
○ Weekday vs. weekend travel costs: Weekdays may offer discounts on
accommodations.
○ Early bookings may provide discounted rates on transportation and
accommodation.
3. Document findings and use these to make cost-effective choices for the trip.

Step 3: Abstract Major Steps

1. Simplify the focus by listing only critical steps necessary for planning:
○ Choose a transport mode (e.g., car rental) based on cost and convenience.
○ Select accommodation that fits the group size and budget.
○ Decide on main activities (one per day) to minimize costs while ensuring
variety.
○ Set a daily budget for meals to keep overall costs within budget limits.
2. Create a Budget Summary:
○ Divide the $3,000 total into estimated amounts per category:
■ Transportation: % (₦ )
■ Accommodation: % (₦ )
■ Itinerary/Activities: % (₦ )
■ Meals: % (₦ )
3. Adjust based on necessity, prioritizing accommodation and transportation.

Step 4: Design an Algorithm for Trip Planning


1. Outline the booking algorithm steps:
Input:
○ Total budget
○ Group size
○ Duration of trip (4 days, 3 nights)
2. Process:
○ Set maximum spend per category based on budget.
○ Compare costs for transport options and choose the one within budget.
○ Check for available accommodations that meet the group’s budget and
needs.
○ Choose activities based on daily budget allocation for the itinerary.
○ Allocate a daily meal budget for each group member.
3. Output:
○ A finalized plan showing transport, accommodation, daily itinerary, and
meal budget within the ₦2,000,000 limit.
4. Yankari Trip Detailed Algorithm:

1. Initialize total budget: ₦1,200,000


2. Calculate maximum spend per category:
○ Transport = ₦400,000
○ Accommodation = ₦500,000
○ Itinerary = ₦200,000
○ Meals = ₦100,000
3. Select transport option within ₦400,000:
○ Identify transport options, such as group rental buses, flights, or trains.
○ Compare costs:
■ For flights, calculate the round-trip cost per person and ensure it’s
within budget.
■ For road transport (bus or rental), estimate fuel and rental fees.
○ If multiple options are under ₦400,000, select the cheapest.
○ Allocate final selected transport cost.
4. Search for accommodation under ₦500,000:
○ Explore available hotels, lodges, or guest houses near Yankari Game Reserve.
○ Prefer group rooms or rentals for cost efficiency.
○ Calculate nightly rate per person, ensuring total stay cost is within the
accommodation budget.
○ Reserve the accommodation that offers the best amenities within the budget.
5. Plan daily itinerary within ₦200,000:
○ List available activities at Yankari Game Reserve (e.g., wildlife tours, hot
springs).
○ Choose one main activity per day that costs less than ₦50,000.
○ Sum up the activity costs to ensure they don’t exceed ₦200,000.
○ Allocate itinerary budget to each day’s activity.
6. Allocate daily meal budget of ₦2,000 per person:
○ Calculate total meal cost: ₦2,000 x total number of people x number of days.
○ If the total exceeds ₦100,000, adjust meal plans (e.g., include self-prepared
meals or budget dining).
○ Ensure the final meal allocation stays within the meals budget.
7. Adjust any category to remain within the total budget:
○ If any category exceeds its allocated budget, adjust by:
■ Choosing a lower-cost option in transport or accommodation.
■ Limiting itinerary activities or reducing the meal budget per person.
○ Re-validate that the total remains under ₦1,200,000 before finalizing plans.

Demo Exercise: Automate a Simple Task in Python


Objective: Guide participants through creating a Python program that generates a
personalized thank-you message for customers or team members.

Instructions:
Step 1: Define the Objective

Our goal is to create a function in Python that will automatically generate a thank-you
message when given a person’s name and their completed task or purchase.

Example output:

● Input: Name = "Alice", Task = "submitting the report"


● Output: "Thank you, Alice, for submitting the report!"

Step 2: Open Python or Your IDE

If you’re using an IDE like PyCharm or Jupyter Notebook:

1. Open your IDE or go to an online compiler like https://www.online-python.com or


https://www.pythononline.net
2. Create a new Python file/tab named thank_you_message.py.

Step 3: Write the Python Function

1. Begin by defining a function named thank_you_message.


2. This function will take two parameters:
○ name: The recipient's name (a string).
○ task: The completed task or item they purchased (also a string).
3. Inside the function, use an f-string to format a message that includes the recipient’s
name and the task or purchase.

def thank_you_message(name, task):


message = f"Thank you, {name}, for {task}!"
return message

Step 4: Test the Function with Different Inputs

1. Now, let's test the function by calling it with different names and tasks.
2. Each test will print out the generated message.

# Testing the function with different inputs


print(thank_you_message("Alice", "submitting the report"))
print(thank_you_message("Bob", "purchasing the annual subscription"))
print(thank_you_message("Cathy", "completing the project milestone"))

Step 6: Explanation of Code

1. Function Definition: def thank_you_message(name, task): defines a


function that takes two inputs.
2. Message Creation: message = f"Thank you, {name}, for {task}!"
uses Python's f-string to insert the name and task variables into the thank-you
message.
3. Return Statement: return message sends back the formatted message when
the function is called.
4. Testing: The print() function displays the result of each call to
thank_you_message().

Step 7: Create and Test a Function to Output Acknowledgment of Submitted Reports

1. Be creative and test your function by calling it with different names and tasks.
2. Confirm that each test prints out the correct message.
Hands-On Exercise 3: Automating a Daily Checklist in Python
Objective

Learn how to use Python to create a daily checklist that you can reuse every day by simply
running the script. The checklist will prompt users to complete each task, mark it as "done,"
and display a summary at the end of the day.

Steps for the Exercise

1. Define Tasks: Predefine a list of daily tasks in the script.


2. Interactive Prompts: As the user runs the script, they will be prompted to mark
each task as "done" when completed.
3. Summary: At the end of the checklist, the script will display which tasks were
completed and which were not.

Python Script for the Exercise:


# Step 1: Define a list of daily tasks
tasks = [
"Review emails",
"Plan daily schedule",
"Complete morning report",
"Check project updates",
"Attend team meeting",
"Organize files",
"End-of-day review"
]

# Step 2: Initialize a dictionary to track task status


task_status = {task: "Not done" for task in tasks}

# Step 3: Display tasks and ask user to mark each as done


print("Daily Checklist:")
for task in tasks:
print(f"\nTask: {task}")
response = input("Have you completed this task? (yes/no):
").strip().lower()
if response == "yes":
task_status[task] = "Done"

# Step 4: Show a summary of completed tasks


print("\n--- Daily Checklist Summary ---")
for task, status in task_status.items():
print(f"{task}: {status}")

print("\nEnd of checklist. Great work today!")

How to Run the Exercise

1. Open an online IDE or a Python editor.


2. Copy and paste the script above.
3. Run the script.
4. For each task in the checklist, respond with "yes" or "no" when prompted.
5. At the end, view the summary showing which tasks were completed.

Expected Output
Initial Output: The script will display each task, one at a time, prompting the user to mark
each as completed.

Daily Checklist:

Task: Review emails


Have you completed this task? (yes/no):

Summary Output: After responding to all tasks, a summary will show which tasks are
"Done" and which are "Not done".

--- Daily Checklist Summary ---


Review emails: Done
Plan daily schedule: Not done
Complete morning report: Done
Check project updates: Done
Attend team meeting: Not done
Organize files: Not done
End-of-day review: Done

End of checklist. Great work today!

You might also like