Help me code a program in python. The code should be simple to read, but advanced enough…
- User
Help me code a program in python. The code should be simple to read, but advanced enough to show a few different things that are possible to do using python.
- Assistant
Here's an example program in Python that showcases a few advanced features of the language:
class BankAccount: def __init__(self, name, balance): self.name = name self._balance = balance def deposit(self, amount): self._balance += amount def withdraw(self, amount): if amount > self._balance: raise Exception("Insufficient balance") self._balance -= amount def __str__(self): return f"{self.name} has a balance of {self._balance}" def interest_calculator(accounts, rate): return [account._balance * rate for account in accounts] def main(): accounts = [ BankAccount("Alice", 1000), BankAccount("Bob", 2000), BankAccount("Charlie", 3000) ] [print(account) for account in accounts] rate = 0.05 interests = interest_calculator(accounts, rate) [print(f"{account.name} earned {interest} in interest") for account, interest in zip(accounts, interests)] if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →