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

Assignment 7

The document outlines a computer assignment involving a budget calculation program that prompts users for their monthly income, fixed expenses, and variable expenses, and calculates the remaining budget. It also includes debugging techniques to address logical errors in the budget calculation, such as using print statements, error handling, logging, unit testing, and code profiling. Additionally, references for further reading on informatics and Python programming are provided.

Uploaded by

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

Assignment 7

The document outlines a computer assignment involving a budget calculation program that prompts users for their monthly income, fixed expenses, and variable expenses, and calculates the remaining budget. It also includes debugging techniques to address logical errors in the budget calculation, such as using print statements, error handling, logging, unit testing, and code profiling. Additionally, references for further reading on informatics and Python programming are provided.

Uploaded by

Mukbs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Assignment 7

Question one

1. Prompt for Monthly Income:


 Prompt the user to input their monthly income using the input function and store the
value in a variable income.
2. Prompt for Fixed Expenses:
 Prompt the user to input their fixed expenses (e.g., rent, utilities) and store the total in a
variable fixed_expenses.
3. Prompt for Variable Expenses:
 Initialize an empty list variable_expenses to store the variable expenses.
 Use a while loop to iteratively prompt the user to input their variable expenses (e.g.,
groceries, entertainment) until they indicate they have no more expenses to add.
 Within the loop, use the append function to add each expense to
the variable_expenses list.
4. Conditional Selection for Expense Scenarios:
 Use conditional selection (if-elif-else) to handle different expense scenarios, such as
when the fixed expenses exceed the monthly income or when there are no variable
expenses.
5. Calculate Remaining Budget:
 Calculate the total expenses by summing the fixed and variable expenses.
 Calculate the remaining budget by subtracting the total expenses from the monthly
income.
6. Display Remaining Budget:
 Display the remaining budget to the user.
Illustrations.

def. calculate_budget():
Step 1: Input monthly income income =
float(input("Enter monthly income: $"))
Step 2: Fixed expenses fixed_expenses = 0.0 num_fixed =
int(input("Number of fixed expenses: ")) for i in
range(num_fixed): expense = float(input(f"Fixed expense #{i+1}:
$")) fixed_expenses += expense

Step 3: Variable expenses with conditional categorization


variable_expenses = 0.0 num_variable = int(input("Number of
variable expenses: ")) for i in range(num_variable): expense =
float(input(f"Variable expense #{i+1}: $")) category =
input("Category (groceries/entertainment/other): ").lower()
Conditional selection for warnings if category == "entertainment"
and expense > 0.1 * income: print("Warning: Entertainment
exceeds 10% of income!") variable_expenses += expense

Step 4: Calculate remaining budget remaining =


income - (fixed_expenses + variable_expenses)
print(f"Remaining budget: ${remaining:.2f}")
calculate_budget()

Question Two.
Debugging the Logical Error
To identify and rectify the logical error causing occasional miscalculation of the remaining
budget, we can use the following debugging techniques and tools:
1. Print Statements:
 Insert print statements at key points in the algorithm to display the intermediate values of
variables (e.g., income, fixed_expenses, variable_expenses, total expenses, remaining
budget).
 This allows us to track the flow of the algorithm and identify any unexpected values.
2. Error Handling:
 Implement error handling to catch any unexpected user inputs that may lead to incorrect
calculations.
 For example, we can use try-except blocks to handle potential input errors and provide
informative error messages to the user.
3. Logging:
 Utilize logging to record the values of variables and the flow of the algorithm during
execution.
 This can help in identifying patterns or specific inputs that lead to the logical error.
4. Unit Testing:
 Create unit tests to verify the correctness of individual components of the algorithm, such
as the calculation of total expenses and remaining budget.
 This can help isolate the specific part of the algorithm causing the miscalculation.
5. Code Profiling:
 Use code profiling tools to analyze the performance of the algorithm and identify any
inefficiencies or unexpected behavior.
 This can reveal potential areas of the code where the logical error may be occurring.

REFERENCES.
1. Yatsko, A., & Suslow, W. (2016). Insight into theoretical and
applied informatics: Introduction to information technologies
and computer science. Walter de Gruyter GmbH.
2. https://www.python.org/about/gettingstarted/
3. https://www.freecodecamp.org/news/python-code-examples-sample-
script-coding-tutorial-for-beginners/

You might also like