Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python question, please add comments on how you do it. Define the following three functions inside a program named decision_making.py . For each task, be

Python question, please add comments on how you do it.

Define the following three functions inside a program named decision_making.py. For each task, be sure to choose the most appropriate "if" structure for the decisions that need to be made. Also, be certain to name your program and functions exactly as described. Import any modules a function needs inside the function that needs it.

Testing: you are provided with a test program, test_hw6.pyimage text in transcribed. Download the program and place it in the same folder as your decision_making.py program. Run test_hw6.py to test your program.

Task 1:

Write a function median(list_name) that takes a list of numbers as an argument and RETURNS the median value. Your function should work for any list of numbers.

If there is an odd number of data values, the median will be the value in the middle of the sorted list. If there is an even number of data values, the median is the mean (or average) of the two data values in the middle of the sorted list. So, for the data set [1, 1, 2, 5, 6, 6, 9], the median is 5. For the data set [1, 1, 2, 6, 6, 9], the median is 4. DO NOT assume that the list argument passed to your function will be in sorted order.

Tips:

To sort a list: use the built-in Python function, sorted(). Following is an example typed into the Python shell.

>>> myList = [5, 4, 10, 6, 7, 8, 9, 1, 2] >>> sorted(myList) [1, 2, 4, 5, 6, 7, 8, 9, 10]

Task 2:

Write a function called daily_boost(day) that takes as a parameter a day of the week and then PRINTS an encouraging statement based on which day of the week was passed to the function. Make sure that the statement is different for each day of the week. Note: while it's possible to solve this problem using lists, your function should instead use an if-elif statement.

For example, the following calls to your function (below) should print the statements you assigned to Monday and to Friday, respectively. The two statements shown as output below (after the "==>") are just examples -- your statements may be different.

daily_boost("Monday") ==> "It's the beginning of the week and the start of something brand new!" daily_boost("friDay") ==> "It's almost the weekend!"

Task 3:

Write a function called choose_pet_name(species, gender) that accepts two parameters: a species and a gender. Inside the function, create four lists of pet names: one for female cats, one for male cats, one for female dogs, and one for male dogs. Make sure each list has at least 5 appropriate, non-offensive names in it. Assign each list to a separate variable. For example, following are some partial lists to get you started.

cat_female = ["Kitty", "Girlfriend", "Daisy", ...] cat_male = ["Murphy", "Mac", "Tom", ...] dog_female = ["Pepper", "Fluffy", ...] dog_male = ["Spot", "Rover", ...]

Based on the values passed to the species parameter (either "cat" or "dog") and to the gender parameter ("male", "female" or "any"), your program should randomly choose a name from the corresponding list of names. If the gender is "any" or any other value, your function should randomly choose any of the names that are listed for the species (that is, from the female and male names combined) without concern for the gender. (Hint: you can create a new list by adding together two lists.) Your function should RETURN the chosen name. Make sure that your function works regardless of the case of the values passed to the function. Also, your function should return None if anything other than (case-insensitive) "cat" or "dog" is passed for the species.

For example (based on sample lists):

choose_pet_name("Cat", "FEMALE") ==> "Girlfriend" choose_pet_name("doG", "Any") ==> "Fluffy" choose_pet_name("doG", "Any") ==> "Rover"

Additional Assignment Criteria

Place the code you write for the tasks in a single Python file called decision_making.py.

Include a header with the filename, brief descriptions of each program, your name and a date.

Add line comments before each task and at other appropriate sections of your code.

In addition to meeting the stated requirements found in this description, your assignment will be graded for correct use of Python concepts and syntax covered to date in the course.

Test your program using the provided test program. For tasks 2 and 3, you should visually confirm that the actual output is correct based on the values you provided in your lists.

Download test_hw6.py into the same folder where decision_making.py is located

Make sure decision_making.py is named EXACTLY decsision_making.py

Load test_hw6.py into Idle or Thonny.

Run test_hw6.py

Examine your results. For tasks 2 and 3, you should confirm that the actual output is correct based on the values you provided in your lists.

If you test your functions in a main function inside your program, be sure to remove or comment out the call to your main function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

What is the R Square value?

Answered: 1 week ago

Question

Which field has the highest average (mean)?

Answered: 1 week ago

Question

What is the highest outlier from the in-person transactions?

Answered: 1 week ago