Python Exercise 7

Question 1: N.B. This question is worth 5 points! Write a function find_even(L) that takes in a list of integers L and returns all the even numbers in the list. If there is no even number have it raise a ValueError exception. You must test your code by generating importing random and generating random lists of integers.

 

Question 2 Background: Consider the code below for a new class of objects called account that has the attributes described in the docstrings below:

 

class Account:

        """A bank account that has a non-negative balance."""

        def __init__(self, account_holder):

            """Every Account is described using the name of the account holder, which is a string."""

            self.balance = 0

            self.holder = account_holder

        def deposit(self, amount):

            """Increase the account balance by amount and return the new balance."""

            self.balance = self.balance + amount

            return self.balance

        def withdraw(self, amount):

            """Decrease the account balance by amount and return the new balance."""

            if amount > self.balance:

                return 'Insufficient funds'

            self.balance = self.balance - amount

 

            return self.balance

Question 2: N.B. This question is worth 5 points! Using the class account above, write a new subclass hiAccount (note "hi" stands for "high interest") that allows you to earn interest at the rate of .01% per second.

Write a new method called checkBalance for hiAccount that computes hiAccount's value, accounting for the growth of your hiAccount between when the time when the deposit was made and when you invoke checkBalance.

You might want to familiarize yourself with the time module by reading the time documentation

 

Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2024 Codify Tutor. All rights reserved