I've been trying to select scores at random from a .txt file and then finding the average of these randomly selected scores. Below is an example:
James, 0.974
Harry, 0.971
Ben, 0.968
Tom, 0.965
George, 0.964
For the sake of simplicity, I'd just like to select 2 scores at random to start with. See below:
James, 0.974
Harry, 0.971 <---
Ben, 0.968
Tom, 0.965 <---
George, 0.964
The end result would then be (Harry and Tom):
Average = 0.968
Can anyone help? I've been using 'split', 'import random' etc. But I'm not great at putting these all together. This is embarrassing, but here's what I've got so far...
import random
stroke = random.choice(open('stroke.txt').readlines())
for x in stroke:
name, score = stroke.split(',')
score = int(score)
stroke.append((name, score))
print(stroke)