Question

In: Computer Science

Fruits=['mango','apple','orange','banana','grape'] prices=[15,12,17,7,19] 1. Using priceDict, find the price for 'grape'. 2. Add a price of 20...

Fruits=['mango','apple','orange','banana','grape']

prices=[15,12,17,7,19]

1. Using priceDict, find the price for 'grape'.

2. Add a price of 20 for 'pomegranate'.

3. Create a sorted list of all the prices in priceDict.

4. Calculate the average of all the prices in priceDict.

5. Update the price for 'pomegranate' to be 25.

6. Mangos has just sold out. Delete 'mango' and its price from priceDict.

Python

Solutions

Expert Solution

Python code pasted below.

Fruits=["mango","apple","orange","banana","grape"]
prices=[15,12,17,7,19]
#creating an empty dictionary priceDict
priceDict={}
for i in range(len(Fruits)):
#Adding fruits and their prices to a dictionary
priceDict[Fruits[i]]=prices[i]
print("Dictionary priceDict")
print(priceDict)
print()

#Finding the price of grape from priceDict
print("Price for grape is ",priceDict['grape'])
print()

#Add a price of 20 for pomegranate
priceDict['pomegranate']=20

#Calculate a sorted list of all the prices in priceDict
print("Sorted in order of prices")
priceDict={k: v for k, v in sorted(priceDict.items(), key=lambda item: item[1])}
print(priceDict)
print()

#calculate the average of all prices in priceDict()
sum=0
for k,v in priceDict.items():
sum=sum+v
average=sum/len(priceDict)
print("Average of all prices=",average)
print()

#update price of pomegranate to 25
priceDict['pomegranate']=25
print("priceDict after updating the price of pomegranate to 25")
print(priceDict)
print()

#delete mango and price from priceDict
del priceDict['mango']
print("priceDict after deleting mango")
print(priceDict)

Python code in IDLE pasted for better understanding of the indent.

Output Screen


Related Solutions

Washington can grow 1 grape or 26 apple bushels per acre and California can grow 20...
Washington can grow 1 grape or 26 apple bushels per acre and California can grow 20 of either. 1.For Washington to grow one grape, it must give up __ apples. a)For California to grow one grape, it must give up __ apple. b)The absolute advantage in apple production is had by: 2.The absolute advantage in grape production is had by: a)The comparative advantage in apple production is had by: b)The comparative advantage in grape production is had by: 3.The difference...
Prices as shown on 20 Dec 2018 Apple Inc : Current spot price: $ 150   CALLS...
Prices as shown on 20 Dec 2018 Apple Inc : Current spot price: $ 150   CALLS PUTS Dec Jan Feb Strike Price Dec Jan Feb 5 8.85 - 149 2.67 6.6 7.93 4.25 8.35 9.65 150 3.15 7 8.38 2.97 7 7.95 152 4.2 8.1 9.5 1.88 5.83 7.36 155 5.85 9.3 10.64 11.1 Construct a profit/loss for a buyer of Jan Call at 155 strike price 11.2 Construct a profit/loss for a seller of Jan Call at 155 strike...
Steps a) add 20 grams of oysters to 20 mL of saline to give a 1:2...
Steps a) add 20 grams of oysters to 20 mL of saline to give a 1:2 dilution slurry b) Transfer 5 grams of the slurry into a conical tube. c) Prepare a 1:10 serial dilution by adding 20mL of saline to the measured 5 g of slurry ( this step effects a 1:5 dilution but that sample was already diluted 1:2) d) Prepare a 10^-1, 10^-2, and 10^-3 serial dilution in culture tubes with 9 mL of saline e) plate...
Using excel, find the price of a 20-year $2000 par bond with 6% annual coupons for...
Using excel, find the price of a 20-year $2000 par bond with 6% annual coupons for yield rates starting at 0 and increasing by .001 (.1%) until .15 (15%). Graph the bond prices (price on the y-axis and yield on the x-axis). Answer the following questions: Describe your graph. What happens to bond prices when rates increase? At what rate does the bond sell for par? (When is the price $2000)? At what rates is the bond selling for a...
demand p=20-q total cost =20+q+q^2 find price ,quantity, and profit for a monoplist firm price ,quntitiy,...
demand p=20-q total cost =20+q+q^2 find price ,quantity, and profit for a monoplist firm price ,quntitiy, and profit for purely commpetitive firm
1. (a) Using the concept of price elasticity of demand explain why companies set different prices...
1. (a) Using the concept of price elasticity of demand explain why companies set different prices for the same product in different markets. (b) Apart from price elasticity of demand examine the other factors which influence a company when setting a price.
Price Control In the space provided (1) Explain the functionality of prices (2) graph an unregulated...
Price Control In the space provided (1) Explain the functionality of prices (2) graph an unregulated apartment market. Please label the supply curve, market demand, equilibrium point as (a), price equilibrium as $400, and quantity equilibrium as 1,000. (3) Now assume the government steps in and sets a price ceiling (rent Control). Draw this line, label it (Pc), and detail Consumer surplus, Producer Surplus, and deadweight lost.
1) Describe the Apple Watch product line pricing strategy. 2) Find or Share updated information of...
1) Describe the Apple Watch product line pricing strategy. 2) Find or Share updated information of Apple watch since it was launched in 2015 from various international markets. 3) How does Apple Watch change consumers' lifestyle
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
using 2 semaphores and 1 mutex: (solve in simple c++ language for linux terminal and add...
using 2 semaphores and 1 mutex: (solve in simple c++ language for linux terminal and add comments please) The barber shop has one barber (a thread), one barber chair, and n chairs for waiting customers (semaphore), if any, to sit on. If there are no customers (each customer is a thread) present, the barber sits down in the barber chair and falls asleep. When a customer arrives, he has to wake up the sleeping barber. If additional customers arrive while...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT