I am new in python.
(我是python的新手。)
my question how to take probability in python. (我的问题如何在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 ?
(A级有分数40 10 10 20 10我如何从这些分数中得出概率,例如10是总数5的3倍。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('', 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) + '%')
ask by Humair Ali translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…