Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 5 Precious metals are assets that people acquire to hedge against inflation. Here are the prices as of February 6, 2020. Precious Metal Spot

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Problem 5 Precious metals are assets that people acquire to hedge against inflation. Here are the prices as of February 6, 2020. Precious Metal Spot Price ($/Oz) (dollars per ounce) $ Change Gold 1559.33 4.00 Silver 17.68 0.01 Platinum 967.95 (.19) Palladium 2445.30 (6.36) You'll be writing a program to help manage your funds. Some reflection before you begin programming-the problem is much simpler than it might seem. We'll give an example. Suppose you have $100. Apples cost $27 each. What's the maximal number of apples you can buy and what amount of money will be left over? Here's a minisession you should do on your own to help better understand. 1 >>> wallet = 100 2 >>> appleCost = 27 3 >>> apples = wallet/appleCost 4 >>> apples 5 3.7037037037037037 6 >>> import math 7 >>> apples = math.floor(apples) 8 >>> apples 93 10 >>> myFloor = wallet // appleCost 11 >>> myFloor 12 3 13 >>> left = wallet % appleCost 14 >>> left 15 19 16 >>> wallet - apples appleCost 17 19 18 >>> 19 + 3+27 == 100 19 True Assignment No 3 Functions and Choice Page 20 Listing 2: precmetal.py program 1 #imports 2 import math 4 ###################################### 6 # DATA 7 # 8 #All values $/ounce abbreviated $/Oz 9 Gold = 1559.10 10 Silver = 17.68 11 Platinum = 967.95 12 Palladium = 2445.30 14 Au, Ag, Pi, Pa = "AU", "Ag", "P1", "Pa" # to make use of symbols easier 16 account = 100000# $100,000 cash assets 17 Au_amt, Ag_amt, Pl_amt, Pa_amt = 0,0,0,0 18 19 ####################################### 20 #PARAMETERS NOTHING 21 #RETURN amount of money you have 22 #and amount of precious metals 23 def holdings(): print("Your current holdings") print("Account = {0:2f}".format(account)) print("Gold = ", Au_amt) print("Silver = ", Ag_amt) print("Platinum = ", Pl_amt) print("Palladium = ", Au_amt) print 33 #PARAMETERS metal and amount in ounces you want to purchase 34 #RETURN the cost of the amount of metal you're purchasing (Numerical) 35 def precious MetalToDollars (metal, amt): # TODO: Implement Function pass 40 #PARAMETERS metal and amt you want to purchase 41 #RETURN IF you have sufficient funds, purchase that amount in 42 #oz. and add to x_amt and subtract that from account 43 # and RETURN message 44 #If you don't have sufficient funds, RETURN message that you 45 #can't purchase that amount 46 def purchase(metal, amt): Assignment No 3 Functions and Choice Page 21 global account # global is not to be used without being told, # needed specifically for this problem global Au_amt global Ag_amt global Pl_amt global Pa_amt #LEAVE GLOBAL variables # TODO: Implement Function # TODO: Return String specifically # Suggestion: Use format, to do a newline in a string, use in pass 61 ######MAIN###### 62 if __name__=="_main__": holdings() print("{:0.2f)". format (precious MetalToDollars(Au, 4))) print("{:0.2f}".format(precious MetalToDollars(Ag, 100))) print("{:0.2f}".format(precious MetalToDollars(Pa, 23))) print("{:0.2f}".format(precious MetalToDollars(P1, 17))) print() print (purchase (Au, 4)) print(purchase(Ag, 100)) print (purchase(Pa, 23)) print(purchase(P1, 17)) print) holdings print (purchase(P1, 100000)) Assignment No 3 Functions and Choice Page 22 Output precmetal.py Your current holdings Account = 100000.00 Gold = 0 Silver = 0 Platinum = 0 Palladium = 0 6236.40 1768.00 56241.90 16455.15 You have purchased 4 oz. of Au for $ 6236.4 You have $ 93763.6 left in your account You have purchased 100 oz. of Ag for $ 1768.0 You have $ 91995.6 left in your account You have purchased 23 oz. of Pa for $ 56241.9 You have $ 35753.700000000004 left in your account You have purchased 17 oz. of Pl for $ 16455.15 You have $ 19298.550000000003 left in your account Your current holdings Account = 19298.55 Gold = 4 Silver = 100 Platinum = 17 Palladium = 4 You have insufficient funds for 100000 oz. of Pl Deliverables for Programming Problem 5 . Complete the program above. . Only modify functions, do not add code outside of functions The draft is metalurgency.py. . Put your code for this function in a new Python module named precmetal.py. Assignment No 3 Functions and Choice Page 23 Problem 5 Precious metals are assets that people acquire to hedge against inflation. Here are the prices as of February 6, 2020. Precious Metal Spot Price ($/Oz) (dollars per ounce) $ Change Gold 1559.33 4.00 Silver 17.68 0.01 Platinum 967.95 (.19) Palladium 2445.30 (6.36) You'll be writing a program to help manage your funds. Some reflection before you begin programming-the problem is much simpler than it might seem. We'll give an example. Suppose you have $100. Apples cost $27 each. What's the maximal number of apples you can buy and what amount of money will be left over? Here's a minisession you should do on your own to help better understand. 1 >>> wallet = 100 2 >>> appleCost = 27 3 >>> apples = wallet/appleCost 4 >>> apples 5 3.7037037037037037 6 >>> import math 7 >>> apples = math.floor(apples) 8 >>> apples 93 10 >>> myFloor = wallet // appleCost 11 >>> myFloor 12 3 13 >>> left = wallet % appleCost 14 >>> left 15 19 16 >>> wallet - apples appleCost 17 19 18 >>> 19 + 3+27 == 100 19 True Assignment No 3 Functions and Choice Page 20 Listing 2: precmetal.py program 1 #imports 2 import math 4 ###################################### 6 # DATA 7 # 8 #All values $/ounce abbreviated $/Oz 9 Gold = 1559.10 10 Silver = 17.68 11 Platinum = 967.95 12 Palladium = 2445.30 14 Au, Ag, Pi, Pa = "AU", "Ag", "P1", "Pa" # to make use of symbols easier 16 account = 100000# $100,000 cash assets 17 Au_amt, Ag_amt, Pl_amt, Pa_amt = 0,0,0,0 18 19 ####################################### 20 #PARAMETERS NOTHING 21 #RETURN amount of money you have 22 #and amount of precious metals 23 def holdings(): print("Your current holdings") print("Account = {0:2f}".format(account)) print("Gold = ", Au_amt) print("Silver = ", Ag_amt) print("Platinum = ", Pl_amt) print("Palladium = ", Au_amt) print 33 #PARAMETERS metal and amount in ounces you want to purchase 34 #RETURN the cost of the amount of metal you're purchasing (Numerical) 35 def precious MetalToDollars (metal, amt): # TODO: Implement Function pass 40 #PARAMETERS metal and amt you want to purchase 41 #RETURN IF you have sufficient funds, purchase that amount in 42 #oz. and add to x_amt and subtract that from account 43 # and RETURN message 44 #If you don't have sufficient funds, RETURN message that you 45 #can't purchase that amount 46 def purchase(metal, amt): Assignment No 3 Functions and Choice Page 21 global account # global is not to be used without being told, # needed specifically for this problem global Au_amt global Ag_amt global Pl_amt global Pa_amt #LEAVE GLOBAL variables # TODO: Implement Function # TODO: Return String specifically # Suggestion: Use format, to do a newline in a string, use in pass 61 ######MAIN###### 62 if __name__=="_main__": holdings() print("{:0.2f)". format (precious MetalToDollars(Au, 4))) print("{:0.2f}".format(precious MetalToDollars(Ag, 100))) print("{:0.2f}".format(precious MetalToDollars(Pa, 23))) print("{:0.2f}".format(precious MetalToDollars(P1, 17))) print() print (purchase (Au, 4)) print(purchase(Ag, 100)) print (purchase(Pa, 23)) print(purchase(P1, 17)) print) holdings print (purchase(P1, 100000)) Assignment No 3 Functions and Choice Page 22 Output precmetal.py Your current holdings Account = 100000.00 Gold = 0 Silver = 0 Platinum = 0 Palladium = 0 6236.40 1768.00 56241.90 16455.15 You have purchased 4 oz. of Au for $ 6236.4 You have $ 93763.6 left in your account You have purchased 100 oz. of Ag for $ 1768.0 You have $ 91995.6 left in your account You have purchased 23 oz. of Pa for $ 56241.9 You have $ 35753.700000000004 left in your account You have purchased 17 oz. of Pl for $ 16455.15 You have $ 19298.550000000003 left in your account Your current holdings Account = 19298.55 Gold = 4 Silver = 100 Platinum = 17 Palladium = 4 You have insufficient funds for 100000 oz. of Pl Deliverables for Programming Problem 5 . Complete the program above. . Only modify functions, do not add code outside of functions The draft is metalurgency.py. . Put your code for this function in a new Python module named precmetal.py. Assignment No 3 Functions and Choice Page 23

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions