Problem descriptions

1. Implement a function named convert_2_km(), which has no parameters. It converts user input from miles into kilometers. The formula for this conversion is:

1 mile == 1.60934 kilometers.

Steps

  • In a loop, prompt the user for a value in miles
  • If the user enters "STOP", exit the function but DO NOT use the exit() function
  • if the user enters a valid number, show the conversion
  • if the user enters an invalid value, show an error message and prompt again

Example of usage

>>> convert_2_km()
Miles (or STOP): 12
Kilometers: 19.31208
Miles (or STOP): cats
Bad input: cats
Miles (or STOP): 3
Kilometers: 4.82802
Miles (or STOP): stop
Bad input: stop
Miles (or STOP): STOP

Please notice that this function has no self test.

2. Implement a function meal_price(items) that calculates and returns the price for a meal. Its only parameter is a list containing meal item names. The goal of the function is to compute the price of the meal. The only items the function should recognize are:

apple : 0.59
burger : 2.50
drink : 0.99
fries : 1.29

If the list contains anything else, print "Unknown item: ___" and include the item name that is unknown. An unknown item should not stop the process of adding up the price.

3. Implement a function print_change(row) that calculates and prints the difference between adjacent values in a list. The differences are printed separated by commas. For example, if row is [1,2,9], the output should be "1,7" (not including the quote marks) because 2 compared to 1 is 1 greater and 9 compared to 2 is 7 greater. Negative results are expected. If the input was [1,9,2], the expected result is 8,-7.

The length of the list should not matter. You do not need to test for a list that is too short.

4. Implement a function sum_nums(a_list) that sums the numbers from the provided list and returns the result. Note that all the values in the list may not be numeric and therefore need to be skipped. For example, sum_nums([5,'11',27,3,'cat']) should return 35. The values '11' and cat are skipped.

Use a list comprehension to solve this problem.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.