Hello mate,
Import the random library and assign a random number to a variable for each of the text files, read in the text files and then use the random number as an index point for each list.
It would be easier to do it from a csv using numpy - EG:
Import the random library and assign a random number to a variable for each of the text files, read in the text files and then use the random number as an index point for each list.
It would be easier to do it from a csv using numpy - EG:
import numpy as np list_of_words = np.genfromtxt('words.csv',delimiter = ",")You can then use the random library to give a variable a random number:
import random random_number = random.randint(1, 10)And then you can use that to choose the item from the list:
print(list_of_words[random_number])If you have a varied number of items on each list you could also do:
import numpy as np import random list_of_words = np.genfromtxt('words.csv',delimiter = ",") x = int(len(list_of_words)) random_number = random.randint(1, x)You could then make a random order generator by using random number generation and a series of if statements:
#random number made x #random number made y #random number made z if x > y and x > z: if y > z: print (list[x] + list[y] + list[z]) if z > y: print(list[x] + list[z] + list[y]) #and so on
while dad_has_cigs == True: happiness = True if dad_has_cigs == False: print("Dad come home!") happiness = not happiness break