<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Exercise from Think Stats, 2nd Edition (thinkstats2.com)<br>
Allen Downey
Read the pregnancy file.
Step1:  Select live births, then make a CDF of <tt>totalwgt_lb</tt>.
Step2:  Display the CDF.
Step3:  Find out how much you weighed at birth, if you can, and compute CDF(x). 
If you are a first child, look up your birthweight in the CDF of first children; otherwise use the CDF of other children.
Compute the percentile rank of your birthweight
Compute the median birth weight by looking up the value associated with p=0.5.
Compute the interquartile range (IQR) by computing percentiles corresponding to 25 and 75. 
Make a random selection from <tt>cdf</tt>.
Draw a random sample from <tt>cdf</tt>.
Draw a random sample from <tt>cdf</tt>, then compute the percentile rank for each value, and plot the distribution of the percentile ranks.
Generate 1000 random values using <tt>random.random()</tt> and plot their PMF.
Step4:  Assuming that the PMF doesn't work very well, try plotting the CDF instead.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import nsfg
preg = nsfg.ReadFemPreg()
Explanation: Exercise from Think Stats, 2nd Edition (thinkstats2.com)<br>
Allen Downey
Read the pregnancy file.
End of explanation
import thinkstats2 as ts
live = preg[preg.outcome == 1]
wgt_cdf = ts.Cdf(live.totalwgt_lb, label = 'weight')
Explanation: Select live births, then make a CDF of <tt>totalwgt_lb</tt>.
End of explanation
import thinkplot as tp
tp.Cdf(wgt_cdf, label = 'weight')
tp.Show()
Explanation: Display the CDF.
End of explanation
import random
random.random?
import random
thousand = [random.random() for x in range(1000)]
thousand_pmf = ts.Pmf(thousand, label = 'rando')
tp.Pmf(thousand_pmf, linewidth=0.1)
tp.Show()
t_hist = ts.Hist(thousand)
tp.Hist(t_hist, label = "rando")
tp.Show()
Explanation: Find out how much you weighed at birth, if you can, and compute CDF(x). 
If you are a first child, look up your birthweight in the CDF of first children; otherwise use the CDF of other children.
Compute the percentile rank of your birthweight
Compute the median birth weight by looking up the value associated with p=0.5.
Compute the interquartile range (IQR) by computing percentiles corresponding to 25 and 75. 
Make a random selection from <tt>cdf</tt>.
Draw a random sample from <tt>cdf</tt>.
Draw a random sample from <tt>cdf</tt>, then compute the percentile rank for each value, and plot the distribution of the percentile ranks.
Generate 1000 random values using <tt>random.random()</tt> and plot their PMF.
End of explanation
thousand_cdf = ts.Cdf(thousand, label='rando')
tp.Cdf(thousand_cdf)
tp.Show()
import scipy.stats
scipy.stats?
Explanation: Assuming that the PMF doesn't work very well, try plotting the CDF instead.
End of explanation
<END_TASK>