At the top of your script, put the following multi-line comment with your information:
'''
Your name as registered, with optional nickname in parentheses
CIS 41A Fall 2021
Unit F, Problem F
'''
Write an invoice function.
The function will generate a simple invoice and will have two required arguments and two keyword arguments.
The two required arguments are unitPrice and quantity.
The first keyword argument is shipping, and it has a default value of 10.
The second keyword argument is handling, and it has a default value of 5.
Test it twice from main:
First test: unitPrice 20, quantity 4, and shipping 8 (handling is not specified).
Second test: unitPrice 15, quantity 3, and handling 15 (shipping is not specified).
Don't worry about making the formatting pretty.
Write a printGroupMembers function.
The function prints a list of students who are working together on a group project, as well as the group name.
The function has one required argument, the group name, and one variable-length argument that contains the student names.
Test it twice from main:
First test: Call as follows:
printGroupMembers("Group A", "Li", "Audry", "Jia")
Second test: Create a list as follows:
groupB = ["Group B", "Sasha", "Migel", "Tanya", "Hiroto"]
and then call the function using this list.
For this problem, imagine that there is a complex piece of equipment, perhaps a car or a spacecraft, and that all of its various subsystems periodically send out status messages to be read and evaluated by an overseer system. Each message contains just a small amount of data - perhaps only one or two keywords out of the hundreds of things that overseer system must monitor. However, we will restrict ourselves to only three things: temperature, CO2level, and miscError.
Write an overseerSystem function that has a kwargs argument.
Within the function, see if the keyword temperature exists in kwargs.
If it does, and the temperature is greater than 500,
print a warning with the temperature.
Also see if the keyword CO2level exists in kwargs.
If it does, and the CO2level is greater than .15, print a warning with the CO2level.
Lastly, see if the keyword miscError exists in kwargs.
If it does, print a warning with the miscError number.
Test from main by creating five messages and calling the overseerSystem function with each message.
Message1 is temperature:550
Message2 is temperature:475
Message3 is temperature:450, miscError:404
Message4 is CO2level:.17
Message5 is CO2level:.2, miscError:418
We will be building a very basic baseball simulation, one that simulates one half inning of play.
Note: you don't have to know the rules of baseball in order to complete this problem - everything you need to know will be explained here.
In our simulation, there will be five possible outcomes - out, single, double, triple, home run, each with it's own probability of occuring.
Each of these outcomes will be represented by a short function that you will need to write. Each function does nothing but print the outcome and return a numeric value. Function out returns 0, single returns 1, double rteturns 2, triple returns 3, and homerun returns 4. For example, here's the out function:
def out(): print("Out") return 0
Our simulation will generate outcomes within a loop until three outs have occured, at which time the simulation is complete.
Outcomes will be randomly generated one at a time with the help of Pythons random.choices() method (see this explanation and/or the Python documentation). The sequence parameter used by the choices method is a list of the outcome functions. Parameter weights is a list of probabilities, as given below. The k parameter value will be one, as we only want one outcome at a time. Here's some starter code:
import random outcomes = list of functions - ***you need to write this - list should be in this order: out, single, double, triple, homerun*** probabilities = [70, 18, 5, 1, 6] #chance of an out is 70%, single is 18% and so on. #Start loop here - ***you need to write this*** outcome = random.choices(outcomes, weights = probabilities, k = 1) ...
Note that outcome is a list containing a single element.
OPTIONAL: Calculate how many runs have been scored (if any) based on the return values from the outcome functions. A single advances all runners one base, a double two bases, and so on.
Example output:
Cost (unitPrice x quantity) = 80 Shipping = 8 Handling = 5 Total = 93 Cost (unitPrice x quantity) = 45 Shipping = 10 Handling = 15 Total = 70 Members of Group A Li Audry Jia Members of Group B Sasha Migel Tanya Hiroto Warning: temperature is 550 Misc error #404 Warning: CO2level is 0.17 Warning: CO2level is 0.2 Misc error #418 Out Out Double Single Out
Add the following at the end of the script to show your results:
'''
Execution results:
paste execution results here
'''
Submit your finished py script in Canvas, Problem F.