I am asked to produce a random string using a previously defined value.
THREE_CHOICES = 'ABC'
FOUR_CHOICES = 'ABCD'
FIVE_CHOICES = 'ABCDE'
import random
def generate_answers(n: int) -> str:
'''Generates random answers from number inputted '''
for i in range(0,n):
return random.choice(FOUR_CHOICES)
continue
What I am trying to get happening here is, if I were to plug in 7 into the function I'd get something like "ABDCBBA"
A random 7 character string from the specified letters. However, this code is returning only one random character no matter what number I put in (has to be non-zero).
I don't know what to do here, can someone point me in the right direction?
returnis the end of your function. Always. So accumulate in some manner, and thenreturnthe accumulated value.