COMPUTER PART PROBABILITIES EXAMPLE
As an engineer working in a computer manufacturing company, you are responsible for keeping track of various computer parts used in your products.
You have been given a dictionary containing information about different computer parts and their properties, and your boss has asked you to use Python to calculate the following probabilities related to these computer parts based on the information in the dictionary.
probability of picking a CPU at random
probability of picking a part with brand 'Intel' at random
probability of picking a part with type 'GPU' given that it has brand 'Nvidia'
probability of picking a part with a speed of at least 3.0 GHz given that it is a CPU
probability of picking a part with a size of at least 16 GB given that it is a RAM module
Tip: Using what you already know about probability, you can solve these problems! But there is a formula for calculating conditional probabilities that may be helpful for you as well.
Watch the following video for more information about this formula. P(A|B) = P(A and B) / P(B).
We'll work through these first two parts together, step by step:
First, we'll understand how to build a basic probability calculation function
Then we'll practice using this function to find different probabilities in our computer parts inventory
After we master these basics together, you'll use what you've learned to tackle more complex probability calculations on your own, like finding the chance of picking a high-speed CPU or high-capacity RAM.
Part 1
We've given you a collection of computer parts (CPUs, GPUs, RAM, etc.) stored in what we call a dictionary. Think of it like a digital catalog of all your parts. We will first work to understand how to work with this catalog to figure out basic probabilities.
Watch the video below and follow along to fill in the blanks in our probability calculation function. This function will be your helper tool for all the probability calculations we'll do later.
a) Based on the video, fill in the missing code based below.
b) Run the code. Note - there will be no visible execution, as this is just setting up the function that will be called in later sections.
Part 2
Now that we have our tools set up, let's use them to answer some real questions about our computer parts! We'll solve three different probability problems:
If I randomly pick a part from our inventory, what's the chance it's a CPU?
What's the chance of randomly picking an Intel part?
If we know we picked a Nvidia part, what's the chance it's a GPU?
Watch the video, and follow along to complete this task together.
a) Based on the video, fill in the missing code based below.
b) Run the code & record the probabilities.
Part 3
Now that we've learned how to calculate basic probabilities with our computer parts inventory, it's your turn to tackle some more interesting calculations on your own!
For this task, you'll use these same techniques to calculate two new probabilities:
What's the chance of picking a high-speed CPU (3.0 GHz or faster)?
What's the chance of picking a high-capacity RAM module (16 GB or larger)?
The first part of the code shows you the completed code from everything we learned together. Use that as your guide to fill in the blanks for these new calculations. Remember how we used loops and counters in our earlier examples - you'll need to use similar techniques, but now you'll be checking for values that are greater than or equal to a specific number (like speed ≥ 3.0).