Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
6
Indexable
Never
import math

def calculate_range(data):
    return max(data) - min(data)

def calculate_variance(data, frequencies):
    mean = sum([x * f for x, f in zip(data, frequencies)]) / sum(frequencies)
    squared_diff = [(x - mean) ** 2 for x in data]
    variance = sum([s * f for s, f in zip(squared_diff, frequencies)]) / sum(frequencies)
    return variance

def calculate_standard_deviation(variance):
    return math.sqrt(variance)

# Example grouped data and frequencies
data = [10, 20, 30, 40, 50]
frequencies = [5, 8, 12, 7, 3]

# Calculate and print range, variance, and standard deviation
range_value = calculate_range(data)
variance = calculate_variance(data, frequencies)
std_deviation = calculate_standard_deviation(variance)

print(f"Range: {range_value}")
print(f"Variance: {variance}")
print(f"Standard Deviation: {std_deviation}")


















import statistics

def calculate_range(data):
    return max(data) - min(data)

def calculate_standard_deviation(data):
    return statistics.stdev(data)

def main():
  
    data = [float(x) for x in input("Enter the ungrouped data separated by spaces: ").split()]


    range_value = calculate_range(data)
    print(f"Range: {range_value}")


    std_deviation = calculate_standard_deviation(data)
    print(f"Standard Deviation: {std_deviation}")

if __name__ == "__main__":
    main()
Leave a Comment