I am new in python. my question how to take probability in python. I have a data set like this
Class A there is marks 40 10 10 20 10 How can i take probability from these marks like 10 is 3 times from total 5. 3/5 ?
#!/usr/bin/env python3
"""reducer.py"""
import sys
# Create a dictionary to map marks
Marksprob = {}
# Get input from stdin
for line in sys.stdin:
#Remove spaces from beginning and end of the line
line = line.strip()
# parse the input from mapper.py
ClassA, Marks = line.split('\t', 1)
# Create function that returns probability percent rounded to one decimal place
def event_probability(event_outcomes, sample_space):
probability = (event_outcomes / sample_space) * 100
return round(probability, 1)
# Sample Space
ClassA = 25
# Determine the probability of drawing a heart
Marks = 12
grade_probability = event_probability(Marks, ClassA)
# Print each probability
print(str(grade_probability) + '%')
Aucun commentaire:
Enregistrer un commentaire