hw04
.py
keyboard_arrow_up
School
University of California, Berkeley *
*We aren’t endorsed by this school
Course
61A
Subject
Finance
Date
Feb 20, 2024
Type
py
Pages
3
Uploaded by JudgeScience13298
def merge(lst1, lst2):
"""Merges two sorted lists.
>>> merge([1, 3, 5], [2, 4, 6])
[1, 2, 3, 4, 5, 6]
>>> merge([], [2, 4, 6])
[2, 4, 6]
>>> merge([1, 2, 3], [])
[1, 2, 3]
>>> merge([5, 7], [2, 4, 6])
[2, 4, 5, 6, 7]
"""
new_lst = []
def merge_helper(lst1, lst2):
if len(lst1) == 0 or len(lst2) == 0: # Adds remainder elements of list to new_lst when one is empty and returns
if len(lst1) > 0:
new_lst.extend(lst1)
else:
new_lst.extend(lst2)
return new_lst
if lst1[0] < lst2[0]:
new_lst.append(lst1[0])
return merge_helper(lst1[1:], lst2)
else:
new_lst.append(lst2[0])
return merge_helper(lst1, lst2[1:])
return merge_helper(lst1, lst2)
class Mint:
"""A mint creates coins by stamping on years.
The update method sets the mint's stamp to Mint.present_year.
>>> mint = Mint()
>>> mint.year
2021
>>> dime = mint.create(Dime)
>>> dime.year
2021
>>> Mint.present_year = 2101 # Time passes
>>> nickel = mint.create(Nickel)
>>> nickel.year # The mint has not updated its stamp yet
2021
>>> nickel.worth() # 5 cents + (80 - 50 years)
35
>>> mint.update() # The mint's year is updated to 2101
>>> Mint.present_year = 2176 # More time passes
>>> mint.create(Dime).worth() # 10 cents + (75 - 50 years)
35
>>> Mint().create(Dime).worth() # A new mint has the current year
10
>>> dime.worth() # 10 cents + (155 - 50 years)
115
>>> Dime.cents = 20 # Upgrade all dimes!
>>> dime.worth() # 20 cents + (155 - 50 years)
125
"""
present_year = 2021
def __init__(self):
self.update()
def create(self, coin):
return coin(self.year)
def update(self):
self.year = Mint.present_year
class Coin:
def __init__(self, year):
self.year = year
def worth(self):
coin_age = Mint.present_year - self.year
if coin_age > 50:
return self.cents + (coin_age - 50)
else:
return self.cents
class Nickel(Coin):
cents = 5
class Dime(Coin):
cents = 10
class VendingMachine:
"""A vending machine that vends some product for some price.
>>> v = VendingMachine('candy', 10)
>>> v.vend()
'Nothing left to vend. Please restock.'
>>> v.add_funds(15)
'Nothing left to vend. Please restock. Here is your $15.'
>>> v.restock(2)
'Current candy stock: 2'
>>> v.vend()
'You must add $10 more funds.'
>>> v.add_funds(7)
'Current balance: $7'
>>> v.vend()
'You must add $3 more funds.'
>>> v.add_funds(5)
'Current balance: $12'
>>> v.vend()
'Here is your candy and $2 change.'
>>> v.add_funds(10)
'Current balance: $10'
>>> v.vend()
'Here is your candy.'
>>> v.add_funds(15)
'Nothing left to vend. Please restock. Here is your $15.'
>>> w = VendingMachine('soda', 2)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
What is the extension of Word files?
а.
DOCX
O b. TXT
С.
FIL
O d. DOT
arrow_forward
Which of the following is an option for consolidating data into one table or worksheet?
arrow_forward
Which of the following is a feature of Power Query?
arrow_forward
Which of the following can be used to link two tables together?Select one:a. Primary Keyb. Foreign keyc. Data Dictionaryd. None of the above
arrow_forward
No chatgpt used i will give 5 upvotes typing please
arrow_forward
State the purpose for each of the following six built-in spreadsheet functions. (a) PV(i%, n, A, F) (b) FV(i%, n, A, P) (c) RATE(n, A, P, F) (d ) IRR(first_cell:last_cell) (e) PMT(i%, n, P, F) ( f ) NPER(i%, A, P, F)
arrow_forward
10
arrow_forward
Create a SQL table using your name with the following features:
the columns of your table must include, at least the data types (in this order) and one more of your choice
NOTE: You need to specify a 2 column (i.e 2 attribute
1. varchar (n), // where n covers the string length you want to enter
2. Int,
3. decimal, (precision = 8, scale = 3
4. date.
5. ??? your choice here ???
Table constraints:
1. It has a two column primary key
2. a check constraint on 2 columns, on the decimal and the date field
3. Use '2024-02-18' date as the default on the date field
5. write down your relational schema
5. Create the table, insert at least 4 rows, and do a Select * to show them
example don't just copy these, change the constraint names
arrow_forward
What is the result of inputting lF(5>9,ok,error) into a cell?
#NAME?
ok
error
arrow_forward
I need typing clear urjent no chatgpt used i will give 5 upvotes pls full explain
arrow_forward
Each relational database table contains records (listed in
and attributes (listed in
columns; rows
rows; columns
columns; columns
rows; rows
arrow_forward
typing clear no chatgpt used i will give 5 upvote
arrow_forward
A partial dependency A.) is the result of simultaneous user requests for the same data in a partitioned database environment. B) is a name given to one of the three anomalies that result from unnormalized database tables. c) can exist only in a table with a composite primary key D.) may exist in tables that are normalized at the 2NF
arrow_forward
supposed S= 9 + 9/1.07 + 9/1.07^2 + ...+ 9/1.07^961, Find Value of S. (please break down in step by step)
arrow_forward
not use ai please don't
arrow_forward
Which of the following is an option for consolidating data into one table or worksheet?
Use the VLOOKUP function in a formula
Use the CONSOLIDATE function in a formula
Use the MERGE function in a formula
Use the COMBINE function in a formula
arrow_forward
Work out the two possible values of c3x(x+12) = 3x2 + c2x
arrow_forward
I need typing clear urjent no chatgpt used i will give 5 upvotes
arrow_forward
perform the indicated operation
add - 5x⁴ +2x +1;4x³+9x²+5x-3; 7x⁴3x³+3x
arrow_forward
What is the mode for the following data set: 99,100,99, 100,8,9,8,7,8? Show all works.
arrow_forward
If the following pseudocode were an actual program, what would it display?
Declare Integer a = 5
Declare Integer b = 2
Declare Integer c = 5
Declare Integer result
Set result a % (b+c)
Display result
Select one:
a. 21
b. 0
C.
5
d. 2
arrow_forward
I need typing clear urjent no chatgpt use i will give 5 upvotes
arrow_forward
I need typing clear urjent no chatgpt use i will give 5 upvotes
full explanation
arrow_forward
I need do fast typing clear urjent no chatgpt used i will give 5 upvotes pls full explain
arrow_forward
For the spreadsheet built-in function PV(i%,n,A,F), the only parameter that can be completely omitted is:a. i%b. nc. Ad. F
arrow_forward
A partial dependency a. is the result of simultaneous user requests for the same data in a partitioned database environment. b. is a name given to one of the three anomalies that result from unnormalized database tables. c. can exist only in a table with a composite primary key. d. may exist in tables that are normalized at the 2NF level. e. is none of the above.
arrow_forward
ChatGi X Gincome X > DeepL X
zto.mheducation.com/ext/map/index.html?_con=con&external_browser=0&launchUrl=https%253A%252F%252Fnewconnect.mhe
Questi X
ssignment i
Use the following information for the Quick Studies below. (Algo)
[The following information applies to the questions displayed below.]
On December 31, Hawkin's records show the following accounts.
$ 5,900
1,000
3,600
14,800
Cash
Accounts Receivable
Supplies
Equipment
Accounts Payable
Hawkin, Capital, December 1
Hawkin, Withdrawals
Services Revenue
Wages Expense
Rent Expense
Utilities Expense
HAWKIN
Statement of Owner's Equity
For Month Ended December 31
Hawkin, Capital, December 1
Add: Investments by owner
Hawkin, Capital, December 31
6,400
15,300
1,800
$
16,400
8,000
1,900
1,100
QS 1-16 (Algo) Preparing a statement of owner's equity LO P2
Use the above information to prepare a statement of owner's equity for Hawkin for the month ended December 31. Hint: Owner
investments are $0 for the period.
0
Copia d X
0
0
chat.op X
Log…
arrow_forward
Define and describe the use of following commands with proper syntax and examples: (8)a. PPMT & IPMTb. NPV & IRRc. XNPV & XIRRd. Weekday(), Now(), Today(), Weeknum()
arrow_forward
No chatgpt used typing clear
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Survey of Accounting (Accounting I)
Accounting
ISBN:9781305961883
Author:Carl Warren
Publisher:Cengage Learning
Related Questions
- Which of the following can be used to link two tables together?Select one:a. Primary Keyb. Foreign keyc. Data Dictionaryd. None of the abovearrow_forwardNo chatgpt used i will give 5 upvotes typing pleasearrow_forwardState the purpose for each of the following six built-in spreadsheet functions. (a) PV(i%, n, A, F) (b) FV(i%, n, A, P) (c) RATE(n, A, P, F) (d ) IRR(first_cell:last_cell) (e) PMT(i%, n, P, F) ( f ) NPER(i%, A, P, F)arrow_forward
- 10arrow_forwardCreate a SQL table using your name with the following features: the columns of your table must include, at least the data types (in this order) and one more of your choice NOTE: You need to specify a 2 column (i.e 2 attribute 1. varchar (n), // where n covers the string length you want to enter 2. Int, 3. decimal, (precision = 8, scale = 3 4. date. 5. ??? your choice here ??? Table constraints: 1. It has a two column primary key 2. a check constraint on 2 columns, on the decimal and the date field 3. Use '2024-02-18' date as the default on the date field 5. write down your relational schema 5. Create the table, insert at least 4 rows, and do a Select * to show them example don't just copy these, change the constraint namesarrow_forwardWhat is the result of inputting lF(5>9,ok,error) into a cell? #NAME? ok errorarrow_forward
- I need typing clear urjent no chatgpt used i will give 5 upvotes pls full explainarrow_forwardEach relational database table contains records (listed in and attributes (listed in columns; rows rows; columns columns; columns rows; rowsarrow_forwardtyping clear no chatgpt used i will give 5 upvotearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Survey of Accounting (Accounting I)AccountingISBN:9781305961883Author:Carl WarrenPublisher:Cengage Learning
Survey of Accounting (Accounting I)
Accounting
ISBN:9781305961883
Author:Carl Warren
Publisher:Cengage Learning