Hint Given
Hint: Remember that !=only checks for non-equality between two items, not three. However, you can use !=more than once in the same line.For example, 2 != 3 != 4first checks for non-equality between 2and 3, then 3and 4, but NOT 2and 4.
Answer:
#Program is written in Python
# Comments are used for explanatory purpose
# Program starts here
string = open('PrideAndPrejudice.txt', encoding='utf-8').
read()
#Split words
possiblewords = np.array(string.split())
In []:
# Initialise trial simulation to 10000
simulation = 10000
# Initialise diff to 0
diff = 0
# iterate for possible words in PrideAndPrejudice
for i in np.arange(simulation):
words = np.random.choice(possiblewords, 3) #3 words to search for
#implement the condition in hint above
iflen(words.item(0)) != len(words.item(1)) != len(words.item(2)) != len(words.item(0)):
#calcuate result
diff = diff + 1
chance_of_all_different = diff/simulation
chance_of_all_different