Solution Review: Predicting Election Results
This lesson discusses the solution review to predicting election results.
We'll cover the following...
Solution 1 #
Press + to interact
import numpy as npimport numpy.random as rndrnd.seed(2)people = np.zeros(1000000, dtype='int') # arthur is 0people[490001:] = 1 # ben is 1poll = rnd.choice(people, 1000)polled_for_arthur = len(poll[poll == 0])print('polled for A:', polled_for_arthur)if polled_for_arthur > 500:print('Octavius will predict the wrong winner')else:print('Octavius will predict the correct winner')
Explanation #
-
In line 5, we have ...