0
while("list\n" in animals) :
    animals.remove("list\n")

def getAnimal(animals):
    x = random.randint(1,len(animals))
    while True:
        y = random.randint(1,len(animals))
        if y != x:
            break
    if animals[x].split()[-1] == animals[y].split()[-1]:
        print(animals[x].split()[-1])
    else:
        print(animals[x][:-1], animals[y][:-1])

df = open('genAnimals.txt','w')
for i in range(10):
    df.write(str(getAnimal(animals)))
df.close()

The text file created does not shows each string as None, how can I fix it? The text file shows NoneNoneNone...

Ons Gna
  • 1
  • 2
  • 1
    Where is `animals` assigned? What is your expected output? – Nick Jun 09 '22 at 05:52
  • Does this answer your question? [How is returning the output of a function different from printing it?](https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it) – Sören Jun 09 '22 at 06:15
  • "Does not shows each string as None"? Assuming *animals* is a list (not shown in the question) then your output file will contain NoneNoneNoneNoneNoneNoneNoneNoneNoneNone – DarkKnight Jun 09 '22 at 06:27
  • When you call df.write( str(getAnimal(animals))) the str function gets the string of the returning object of the getAnimal, which is None in your case because this function doesn't return anything – pandy giankoulidis Jun 09 '22 at 08:22
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 09 '22 at 15:27

0 Answers0