Question: Please add sorted numbers, median, and variance to the codes below. One is C# and one is Python. I do not want to remove anything
Please add sorted numbers, median, and variance to the codes below. One is C# and one is Python. I do not want to remove anything already exsiting in the code.
C#:
double sum = 0.0, sumsquared=0.0, min = double.MaxValue, max = double.MinValue;
for (int i = 1; i <= 10; i++)
{
double value;
Console.Write("Enter value number {0}: ",i);
while (!double.TryParse(Console.ReadLine(), out value))
{
Console.Write("Invalid number, reenter value number {0}: ",i);
}
if (value < min) min = value;
if (value > max) max = value;
sum += value;
sumsquared += Math.Pow(value, 2);
}
double avg = sum / 10.0;
double stdev = Math.Sqrt((sumsquared - Math.Pow(sum, 2) / 10.0) / (10.0 - 1));
Console.WriteLine("Sum={0}, Min={1}, Max={2}, Avg={3}, Stdev={4}",sum, min, max, avg, stdev);
Phython:
sum = 0.0
sumsquared = 0.0
min_value = float("inf")
max_value = float("-inf")
for i in range(1, 11):
value = float(input("Enter value number {}: ".format(i)))
if value < min_value:
min_value = value
if value > max_value:
max_value = value
sum += value
sumsquared += value**2
avg = sum / 10
stdev = (sumsquared - sum**2 / 10)**0.5 / (10 - 1)**0.5
print("Sum={0}, Min={1}, Max={2}, Avg={3}, Stdev={4}".format(sum, min_value, max_value, avg, stdev))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
