Question

In: Computer Science

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 discussion, you should first write pseudocode for how you would solve this problem

Please write the Pseudocode for this problem.

Solutions

Expert Solution

// PSEUDOCODE//

procedure getPrice(type, weight)

    if (type = 'Quartz crystal')

        then return 23 * weight

    else if (type = 'Garnet') then

        return 160 * weight

    else if (type = 'Meteorite')

        return 15.5 * weight

end getPrice

procedure getUnit(type)

    if (type = 'Quartz crystal')

        then return 'pound'

    else if (type = 'Garnet') then

        return 'pound'

    else if (type = 'Meteorite')

        return 'gram'

end getUnit

procedure price_of_rocks()

    declare double total_cost <-- 0

    yesOrNo <-- 'Y'

    while (yesOrNo = 'Y' OR yesOrNo = 'y') do

        type <--input("Enter Rock type : ")

        weight <-- input("Enter Weight ( " + getUnit(type) + " ) : ")

        total_cost <-- total_cost + getPrice(type, weight)

        YesOrNo <-- input("Do You wish to Continue(Y/N) : ")

    end while

    return total_cost

end price_of_rocks


Related Solutions

write a program bus management system? using: if else, for loop, do while loop, function, arrays,...
write a program bus management system? using: if else, for loop, do while loop, function, arrays, string, structure
in phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child)....
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters....
Sovle with python 3.8 please. 1, Write a function called same_without_ends that has two string parameters. It should return True if those strings are equal WITHOUT considering the characters on the ends (the beginning character and the last character). It should return False otherwise. For example, "last" and "bask" would be considered equal without considering the characters on the ends. Don't worry about the case where the strings have fewer than three characters. Your function MUST be called same_without_ends. You...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and gerunds. Each parameter is a list of strings, where nouns list has noun strings (such as 'homework'), verbs list has veb strings (such as 'enjoy'), and gerunds list has gerund strings (those -ing words, such as 'studying'). The function will go through all these lists in a systematic fashion to create a list of all possible sentences that use all the noun, verb, and...
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 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...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters,...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters, a list of strings, and a string. This function #should return a list of all the indices at which the #string is found within the list. # #You may assume that you do not need to search inside the #items in the list; for examples: # # search_for_string(["bob", "burgers", "tina", "bob"], "bob") # -> [0,3] # search_for_string(["bob", "burgers", "tina", "bob"], "bae") # -> []...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
Creates a function called biochild. The function has as parameters the number m and lists biomotℎer...
Creates a function called biochild. The function has as parameters the number m and lists biomotℎer and biofatℎer. The lists biomotℎer and biofatℎer contain 0’s and 1’s. For example: biomotℎer = [1,0,0,1,0,1] and biofatℎer = [1,1,1,0,0,1] Both lists have the same length n. The 0’s and 1’s represent bits of information (remember that a bit is 0 or 1). The function has to generate a new list (child). The child list has to have the same length n. child is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT