Question

In: Computer Science

cut = "Emerald" clarity = "VS" color = "E" carat = 1.1 budget = 500 preferred_cuts...

cut = "Emerald"
clarity = "VS"
color = "E"
carat = 1.1
budget = 500
preferred_cuts = ["Emerald", "Cushion", "Princess", "Oval"]

#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.

#Diamonds are typically evaluated according to four aspects:
# - Cut: The way the diamond is cut
# - Clarity: How clear or flawless the diamond is, rated
# as F (the best), IF, VVS, VS, SI, or I (the worst)
# - Color: How colorless the diamond is, rated from "D" (the
# best) to "Z" (the worst)
# - Carat: How large the diamond is, weighed in carats
#
#Cut is usually a matter of personal preference. Clarity,
#color, and carat are matters of value: the clearer, more
#colorless, and larger a diamond is, the greater its value.
#
#Imagine you're shopping for a diamond. You have your
#preferred cuts, and you have a budget in mind. You're shown
#a diamond whose characteristics are represented by the cut,
#color, clarity, and carat variables above. You'll buy the
#diamond if its cost is less than your budget, and if its
#cut is one of your preferred cuts.
#
#At this store, every diamond has a base cost of 100.
#
#For every color rating worse than "D", the cost decreases by
#2%. An "F" color diamond would be worth 0.96 * the diamond
#cost otherwise because "F" is two colors worse than "D".
#
#A diamond's value is doubled for every level of clarity above
#I. A "VVS"-clarity diamond is worth 8 * the diamond cost
#otherwise because "VVS" is three levels higher than I, and
#doubling its value three times raises its value by 8x total.
#
#After finding its price based on color and clarity, its price
#is multiplied by its weight in carats.
#
#Your program should print "I'll take it!" if you will buy the
#diamond, "No thanks" if you will not. To purchase it, its price
#must be less than your budget and its cut must be one of your
#preferred cuts.
#
#HINT: You can find the number of characters between two
#characters by using the ord() function. ord("E") - ord("D")
#is 1; ord("Z") - ord("D") is 22.
#
#HINT 2: We haven't covered lists, but we did cover how to
#see if an item is present in a list using the 'in' operator
#in chapter 2.3.


#Add your code here!

Solutions

Expert Solution

cut = "Emerald"
clarity = "VS"
color = "E"
carat = 1.1
budget = 500
preferred_cuts = ["Emerald", "Cushion", "Princess", "Oval"]

#You may modify the lines of code above, but don't move them!
#When you Submit your code, we'll change these lines to
#assign different values to the variables.

#Diamonds are typically evaluated according to four aspects:
# - Cut: The way the diamond is cut
# - Clarity: How clear or flawless the diamond is, rated
# as F (the best), IF, VVS, VS, SI, or I (the worst)
# - Color: How colorless the diamond is, rated from "D" (the
# best) to "Z" (the worst)
# - Carat: How large the diamond is, weighed in carats
#
#Cut is usually a matter of personal preference. Clarity,
#color, and carat are matters of value: the clearer, more
#colorless, and larger a diamond is, the greater its value.
#
#Imagine you're shopping for a diamond. You have your
#preferred cuts, and you have a budget in mind. You're shown
#a diamond whose characteristics are represented by the cut,
#color, clarity, and carat variables above. You'll buy the
#diamond if its cost is less than your budget, and if its
#cut is one of your preferred cuts.
#
#At this store, every diamond has a base cost of 100.
#
#For every color rating worse than "D", the cost decreases by
#2%. An "F" color diamond would be worth 0.96 * the diamond
#cost otherwise because "F" is two colors worse than "D".
#
#A diamond's value is doubled for every level of clarity above
#I. A "VVS"-clarity diamond is worth 8 * the diamond cost
#otherwise because "VVS" is three levels higher than I, and
#doubling its value three times raises its value by 8x total.
#
#After finding its price based on color and clarity, its price
#is multiplied by its weight in carats.
#
#Your program should print "I'll take it!" if you will buy the
#diamond, "No thanks" if you will not. To purchase it, its price
#must be less than your budget and its cut must be one of your
#preferred cuts.
#
#HINT: You can find the number of characters between two
#characters by using the ord() function. ord("E") - ord("D")
#is 1; ord("Z") - ord("D") is 22.
#
#HINT 2: We haven't covered lists, but we did cover how to
#see if an item is present in a list using the 'in' operator
#in chapter 2.3.


#Add your code here!

# cut is in preferred_cuts
if cut in preferred_cuts :
   # base cost of diamond is 100
   diamond_cost = 100
   # get the difference of the color rating of diamond from best color rating
   rating_diff = ord(color) - ord("D")
   if rating_diff > 0: # color rating > 0, decrease the cost by 2% for every color rating worse than "D"
       diamond_cost = (1-0.02*rating_diff)*diamond_cost
  
   # based on the clarity, double the price of the diamond for every level of clarity above "I"
   if clarity == 'SI':
       diamond_cost = 2*diamond_cost
   elif clarity == 'VS':
       diamond_cost = 4*diamond_cost
   elif clarity == 'VVS':
       diamond_cost = 8*diamond_cost
   elif clarity == 'IF':
       diamond_cost = 16*diamond_cost
   elif clarity == 'F':
       diamond_cost = 32*diamond_cost
  
   # multiply the price of diamond by its weight in carats.
   diamond_cost = diamond_cost*carat
  
   # price of diamond is within the buget
   if diamond_cost <= budget:
       print("I'll take it!")
   else: # price of diamond is over the budget
       print("No thanks")
else: # cut is not in preferred_cuts
   print("No thanks")  
  
#end of program  

Code Screenshot:

Output:


Related Solutions

2M2_IND3. Prices of diamond jewelry are based on the “4Cs” ofdiamonds: cut, color, clarity, and carat....
2M2_IND3. Prices of diamond jewelry are based on the “4Cs” ofdiamonds: cut, color, clarity, and carat. A jeweler is trying to estimate the price of diamond earrings based on color, carats, and clarity. The jeweler has collected some data on 22 diamond pieces and the data is shown in Worksheet IND3. The jeweler wouldlike to build a multiple regression model to estimate the price of the pieces based on color, carats, and clarity.a)Prepare a scatter plot showing the relationship betweenthe...
Prices of diamonds are determined by what is known as the 4 Cs: cut, clarity, color,...
Prices of diamonds are determined by what is known as the 4 Cs: cut, clarity, color, and carat weight. The prices of diamonds go up as the carat weight increases, but the increase is not smooth. For example, the di?erence between the size of a 0.99 carat diamond and a 1 carat diamond is undetectable to the naked human eye, but the price of a 1 carat diamond tends to be much higher than the price of a 0.99 diamond....
Compare and contrast, the Lydia E. Hall theory vs Imogene King theory....400 to 500 words
Compare and contrast, the Lydia E. Hall theory vs Imogene King theory....400 to 500 words
Lydia E. Hall theory vs Dorthea Orem theory compare and contrast 400 to 500 words,
Lydia E. Hall theory vs Dorthea Orem theory compare and contrast 400 to 500 words,
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT