Skip to content

Allow decimal values for bank deposits and withdrawals#38

Merged
dmccoystephenson merged 3 commits intomainfrom
copilot/fix-44c7da9f-143c-46e3-9d11-04ae22aa78a7
Oct 13, 2025
Merged

Allow decimal values for bank deposits and withdrawals#38
dmccoystephenson merged 3 commits intomainfrom
copilot/fix-44c7da9f-143c-46e3-9d11-04ae22aa78a7

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 2, 2025

Summary

This PR enables users to deposit and withdraw decimal amounts (e.g., $10.25, $0.99) at the bank, instead of being limited to whole dollar amounts only.

Changes

Previously, the bank's deposit() and withdraw() methods used int() to parse user input, which would raise a ValueError for any decimal input like "10.50". This PR changes the input parsing to use float() and updates all money formatting to use %.2f instead of %d for consistency.

Modified Files

src/location/bank.py:

  • Changed input parsing from int(input("> ")) to float(input("> ")) in both deposit() and withdraw() methods
  • Updated error messages to use %.2f formatting (e.g., "Try again. Money: $%.2f")
  • Updated success messages to use %.2f formatting (e.g., "$%.2f deposited successfully.")

tests/location/test_bank.py:

  • Added test_deposit_with_decimal() - validates depositing $10.25 from $100.50
  • Added test_withdraw_with_decimal() - validates withdrawing $10.50 from $100.75

Testing

All 64 tests pass, including the 2 new tests that specifically validate decimal input handling. The changes maintain backward compatibility - integer inputs like "10" still work correctly.

Example Usage

Before: User enters 10.50ValueError: invalid literal for int()
After: User enters 10.50 → Successfully deposits/withdraws $10.50

This aligns the bank interface with the existing game mechanics, as player.money and player.moneyInBank are already stored as floats (e.g., moneyInBank starts at 0.01), and the prompts already display values using %.2f formatting.

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow the user to use decimals when depositing/withdrawing at the bank.</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #15

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 2, 2025 06:19
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copilot AI changed the title [WIP] Allow the user to use decimals when depositing/withdrawing at the bank. Allow decimal values for bank deposits and withdrawals Oct 2, 2025
Copilot AI requested a review from dmccoystephenson October 2, 2025 06:23
@dmccoystephenson dmccoystephenson marked this pull request as ready for review October 2, 2025 06:26
@dmccoystephenson dmccoystephenson merged commit c2f0f55 into main Oct 13, 2025
@dmccoystephenson dmccoystephenson deleted the copilot/fix-44c7da9f-143c-46e3-9d11-04ae22aa78a7 branch October 13, 2025 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow the user to use decimals when depositing/withdrawing at the bank.

2 participants