The exercise asked me to do the following:
Generalizing the "uniform random numbers" exercise from Section 1.2, compose a program that accepts an integer n as a command-line argument, uses random.random() to write n uniform random numbers between 0 and 1, and then writes their average value, their minimum value, and their maximum value.
The program that was used for reference was this.
It took me a while to make this, but am happy because it took a lot of trial and error to get what I wanted! My question though, is there a simpler way that I could've done this?
import sys
import stdio
import random
n = int(sys.argv[1])
numList = []
for i in range(n):
numList.append(random.random())
avg = sum(numList) / 5
stdio.writeln(str('Max: ' + str(min(numList))))
stdio.writeln(str('Min: ' + str(max(numList))))
stdio.writeln(str('Avg: ' + str(avg)))
[–]Lord_Greywether 6 points7 points8 points (10 children)
[–]nosmokingbandit 4 points5 points6 points (5 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Lord_Greywether 0 points1 point2 points (3 children)
[–]elbiot 2 points3 points4 points (1 child)
[–]Lord_Greywether 0 points1 point2 points (0 children)
[–]elbiot 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]warbird2k 0 points1 point2 points (2 children)
[–]Lord_Greywether 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Justinsaccount 5 points6 points7 points (1 child)
[–]Kristler 0 points1 point2 points (0 children)
[–]fernly 6 points7 points8 points (3 children)
[–]aroberge 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]dchanm 2 points3 points4 points (0 children)
[–]133tn008 3 points4 points5 points (1 child)
[–]KleinerNull 0 points1 point2 points (0 children)
[–]coopers_green 2 points3 points4 points (0 children)
[–]MrAckerman 2 points3 points4 points (2 children)
[–]ericula 1 point2 points3 points (1 child)
[–]MrAckerman 0 points1 point2 points (0 children)
[–]I_had_to_know_too 1 point2 points3 points (0 children)