{"Hello,Words"}{"Hello,Words"}Here's the pretty-formatted version of the code you provided:
class PaymentCard:
def __init__(self, card_number, card_holder, expiration_date, cvv):
self.card_number = card_number
self.card_holder = card_holder
self.expiration_date = expiration_date
self.cvv = cvv
self.balance = 5000 # Set initial balance to $5000
def add_funds(self, amount):
try:
amount = float(amount)
if amount <= 0:
raise ValueError("Amount must be a positive number")
self.balance += amount
print(f"Added {amount} to card balance. New balance: {self.balance}")
except ValueError as e:
print(f"Error: {e}")
def make_payment(self, amount):
try:
amount = float(amount)
if amount <= 0:
raise ValueError("Amount must be a positive number")
if self.balance >= amount:
self.balance -= amount
print(f"Payment of {amount} successful. Remaining balance: {self.balance}")
else:
print("Insufficient funds. Payment declined.")
except ValueError as e:
print(f"Error: {e}")
# Creating an instance of PaymentCard
my_card = PaymentCard("1234 5678 9012 3456", "John Doe", "12/25", "123")
# Displaying the balance for 3 days
for _ in range(3):
print(f"Current balance: {my_card.balance}")
Changes I made:
- Indented the last print statement as it was falling outside the for loop.
add_funds
method was not adding the amount to the existing balance. Instead, it was replacing the balance with the new amount. Changed the logic to correctly add (+=) the amount.- Changed the Spanish text "Saldo actual: " to English "Current balance: " for consistency