lundi 22 mars 2021

Can the count function be used for strings within a function?

I am trying to make a function that randomly selects from two options nine times and returns the number of times each option was chosen. However, each time I try to run the code, the count function returns [None].

 import random
topic=["Insomnia","REM Sleep Disorder"]
def func():
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))
  print(random.choice(topic))


  
x=[func()]
y=x.count("Insomnia")
print(x)

What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire