0% found this document useful (0 votes)
10 views6 pages

Python Bug Debugging Worksheet V2

The document outlines a debugging worksheet for pseudocode, focusing on identifying and fixing bugs and logic errors in three different programming tasks: filtering names, processing online orders, and generating a temperature report. Each task includes specific prompts and pseudocode, with sections for users to identify issues, explain the problems, and provide fixes. The document emphasizes the importance of debugging and logical flow in programming.

Uploaded by

203436688fcs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Python Bug Debugging Worksheet V2

The document outlines a debugging worksheet for pseudocode, focusing on identifying and fixing bugs and logic errors in three different programming tasks: filtering names, processing online orders, and generating a temperature report. Each task includes specific prompts and pseudocode, with sections for users to identify issues, explain the problems, and provide fixes. The document emphasizes the importance of debugging and logical flow in programming.

Uploaded by

203436688fcs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Pseudocode Debugging Worksheet: Finding Bugs

and Logic Errors


Directions
Read each prompt and the pseudocode that attempts to solve it.
3 Each
bugs section
or logic
has
errors hidden across multiple interacting functions.

For each section:

1. Identify 3 issues in the code.


2. Explain why each issue is a problem.
3. Write the fix for each issue.

Part 1: Filtering and Formatting Names


Prompt
Write a program that takes a list of names and a minimum length. The program should:

• create a filtered list of names whose length is greater than or equal to the minimum length
• convert each kept name to uppercase
• sort the final list alphabetically
• print the final formatted list

Pseudocode

FUNCTION keepLongNames(nameList, minLength)


SET results TO empty list

FOR each name IN nameList


IF length(name) > minLength
ADD minLength TO results
END IF
END FOR

RETURN results
END FUNCTION

FUNCTION makeUppercase(names)

1
SET upperNames TO empty list

FOR each name IN names


ADD uppercase(name) TO upperNames
END FOR

RETURN upperNames
END FUNCTION

FUNCTION sortNames(names)
SORT names
END FUNCTION

FUNCTION buildNameReport(nameList, minLength)


SET filtered TO getLongNames(nameList, minLength)
SET uppercaseNames TO makeUppercase(filtered)
SET sortedNames TO sortNames(uppercaseNames)
RETURN sortedNames
END FUNCTION

SET names TO ["Ava", "Jonathan", "Mia", "Charlotte", "Eli", "Amelia"]


SET report TO buildNameReport(names, 4)
DISPLAY "Final names: " + report

Find the 3 issues and fixes

Issue 1

Issue:

Fix:

Issue 2

Issue:

Fix:

Issue 3

Issue:

Fix:

2
Part 2: Processing Online Orders
Prompt
Write a program that takes a list of item prices from an online order and:

• creates a discounted list where each item gets 10 dollars off


• calculates the final total of the discounted prices
• determines whether shipping is Free Shipping (if the total is at least 50), or Shipping Required
otherwise
• creates a final order summary message and prints it

Pseudocode

FUNCTION applyDiscounts(priceList)
SET discountedPrices TO empty list

FOR each price IN priceList


ADD price + 10 TO discountedPrices
END FOR

RETURN discountedPrice
END FUNCTION

FUNCTION calculateTotal(priceList)
SET total TO 0

FOR each price IN priceList


SET total TO total + price
END FOR

RETURN priceList
END FUNCTION

FUNCTION getShippingStatus(total)
IF total >= 50
RETURN "Shipping Required"
ELSE
RETURN "Free Shipping"
END IF
END FUNCTION

FUNCTION buildOrderSummary(total, shippingStatus)


RETURN "Order total: $" + total + " - " + shippingStatus
END FUNCTION

3
FUNCTION processOrder(prices)
SET discounted TO applyDiscounts(prices)
SET finalTotal TO calculateTotals(discounted)
SET shipping TO getShippingStatus(finalTotal)
SET summary TO buildOrderSummary(finalTotal, shipping)
RETURN summary
END FUNCTION

SET prices TO [25, 18, 40]


SET result TO processOrder(prices)
DISPLAY result

Find the 3 issues and fixes

Issue 1

Issue:

Fix:

Issue 2

Issue:

Fix:

Issue 3

Issue:

Fix:

Part 3: Weekly Temperature Report


Prompt
Write a program that takes a list of temperatures and:

• calculates the average temperature


• determines whether the week was Warm if the average is greater than or equal to 70, or Cool
otherwise
• creates a summary sentence with the average and the label

4
• prints the summary sentence

Pseudocode

FUNCTION calculateTotal(temps)
SET total TO 0

FOR each temp IN temps


SET total TO temp
END FOR

RETURN total
END FUNCTION

FUNCTION getAverageTemp(temps)
SET total TO calculateTotal(temps)
SET average TO total / length(temps)
DISPLAY average
END FUNCTION

FUNCTION getLabel(avg)
IF avg >= 70
RETURN "Cool"
ELSE
RETURN "Warm"
END IF
END FUNCTION

FUNCTION buildSummary(avg, label)


RETURN "Average temperature: " + avg + " - " + label
END FUNCTION

FUNCTION weeklyReport(temps)
SET avg TO averageTemp(temps)
SET label TO getLabel(avg)
SET summary TO buildSummary(avg, label)
RETURN summary
END FUNCTION

SET weekTemps TO [68, 72, 70, 75, 69]


SET finalReport TO weeklyReport(weekTemps)
DISPLAY finalReport

5
Find the 3 issues and fixes

Issue 1

Issue:

Fix:

Issue 2

Issue:

Fix:

Issue 3

Issue:

Fix:

You might also like