Question

In: Computer Science

#Write a function called wish_list. wish_list should have #four parameters, in this order: # # -...

#Write a function called wish_list. wish_list should have
#four parameters, in this order:
#
# - a list of strings, representing a list of items on a
# wish list
# - a string, representing a particular item
# - a float, representing the cost of this item
# - a float, representing your budget
#
#If the item is on the list and you can afford it (cost is
#less than or equal to budget), return the string,
#"You should buy a [item name]!", replacing [item name]
#with the string.
#
#If the item is on the list but you can't afford it,
#return the string, "You should save up for a [item name]!",
#replacing [item name] with the string.
#
#If the item is not on the list, you should return the
#string "You probably don't want to buy a [item name].",
#replacing [item name] with the string.
#
#HINT: You do not need a loop to solve this. You can use
#one, but you don't need one.

Solutions

Expert Solution

# Write a function called wish_list. wish_list should have
# four parameters, in this order:
#
# - a list of strings, representing a list of items on a
# wish list
# - a string, representing a particular item
# - a float, representing the cost of this item
# - a float, representing your budget
#
# If the item is on the list and you can afford it (cost is
# less than or equal to budget), return the string,
# "You should buy a [item name]!", replacing [item name]
# with the string.
#
# If the item is on the list but you can't afford it,
# return the string, "You should save up for a [item name]!",
# replacing [item name] with the string.
#
# If the item is not on the list, you should return the
# string "You probably don't want to buy a [item name].",
# replacing [item name] with the string.
#
# HINT: You do not need a loop to solve this. You can use
# one, but you don't need one.
def wish_list(items, item, cost, budget):
    if item in items:
        if cost <= budget:
            return "You should buy a {}!".format(item)
        else:
            return "You should save up for a {}!".format(item)
    else:
        return "You probably don't want to buy a {}.".format(item)

Related Solutions

#Write a function called solve_right_triangle. The function #solve_right_triangle should have three parameters: opposite, #adjacent, and use_degrees....
#Write a function called solve_right_triangle. The function #solve_right_triangle should have three parameters: opposite, #adjacent, and use_degrees. opposite and adjacent will be #floats, and use_degrees will be a boolean. use_degrees #should be a keyword parameter, and it should have a #default value of False. # #The function should return a tuple containing the #hypotenuse and angle of the right triangle (in that order). #If use_degrees is False, the angle should be in radians. #If use_degrees is True, the angle should be...
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings....
using python 1. #Write a function called multiply_file_by_index. This function #should take two parameters, both strings. The first string is #the filename of a file to which to write (output_file), and #the second string is the filename of a file from which to read #(input_file). # #In the input file, there will be an integer on every line. #To the output file, you should write the integer from the #original file multiplied by the line number on which it #appeared....
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and...
Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters.
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock...
Write a function called price_of_rocks. It has no parameters. In a while loop, get a rock type and a weight from the user. Keep a running total of the price for all requested rocks. Repeat until the user wants to quit. Quartz crystals cost $23 per pound. Garnets cost $160 per pound. Meteorite costs $15.50 per gram. Assume the user enters weights in the units as above. Return the total price of all of the material. Using Python For this...
Write a function in R named counts. This function should take as parameters a numeric vector...
Write a function in R named counts. This function should take as parameters a numeric vector x and also a number indicating a number of bins n. The function will consider the range [min(x),max(x)], and then consider a parti- tion of this interval into n non-overlapping equally sized half open intervals: I1 = [min(x),b1),I2 = [b1,b − 2),...,In = (bn−1,max(x)]. Note that since the intervals are equally sized, the value of bi is constrained. The function will then return a...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
Write a function called printChList that takes as its parameters a character array, its size, and...
Write a function called printChList that takes as its parameters a character array, its size, and output file stream. The function should print the contents of the array to the output file. code with c++ and detail explaination
Q4. Please write a function Calculate_integer_division(). Your function should accept two parameters num1 and num2 and...
Q4. Please write a function Calculate_integer_division(). Your function should accept two parameters num1 and num2 and return the result of integer division of num1 by num2. So if num1 is 9 and num2 is 2, the function should return 4. Call your function and print out the result. Q5. Please print out the following with the help of a range() function: 200, 400, 600, 800 Q6. Please print 'Go.' if the traffic light is green, 'Wait.' if it's yellow and...
Write a method called splitArray which will receive four parameters as follows: Original array Array of...
Write a method called splitArray which will receive four parameters as follows: Original array Array of multiples Array of not multiples Number to compare if the values within the original array are multiples of Assuming that always the original array will contain half values as multiples and half as not multiples. Your method should return the numbers within the original array that are multiples of the last parameter in the array of multiples (second parameter). Furthermore, your method should return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT