Advertisement
igorhorst

Code Snippets

Mar 27th, 2024 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. # Given probabilities in the screenshot, let's verify if they indeed sum up to 1.
  2. # Probabilities listed are: 1/16 (six times) and 1/48 (two times).
  3.  
  4. total_probability = (1/16) * 6 + (1/48) * 2
  5. total_probability
  6.  
  7. # Output: 0.4166666666666667
  8. —-
  9. from fractions import Fraction
  10.  
  11. # Convert the total probability to a fraction
  12. fraction_total_probability = Fraction(total_probability).limit_denominator()
  13. fraction_total_probability
  14.  
  15. # Output: Fraction(5,12)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement