In: Computer Science
Given the names of employees in an office: employees = ["Matthew", "Anna", "Curtis", "Jane", "Yang", "Tammie"]
Using the Random library in Python, create two codes that: A. Draws a random sample (without replacement) of 2 employees. Saves and displays the sample. B: Draws a random sample (with replacement) of 4 employees. Save and Displays the sample
A)
.
import random
# Given the names of employees in an office:
employees = ["Matthew", "Anna", "Curtis", "Jane", "Yang", "Tammie"]
# A. Draws a random sample(without replacement) of 2 employees.
first_sample = random.sample(employees, 2)
# Saves and displays the sample.
print(first_sample)
.
Screenshot:
Output:
.
B)
.
import random
# Given the names of employees in an office:
employees = ["Matthew", "Anna", "Curtis", "Jane", "Yang", "Tammie"]
# B: Draws a random sample(with replacement) of 4 employees.
second_sample = []
for i in range(4):
second_sample += random.sample(employees, 1)
# Save and Displays the sample
print(second_sample)
.
Screenshot:
Output:
.