dimanche 11 septembre 2022

Grammatically correct indefinite article in Python

I am creating a random sentence generator that can apply the correct indefinite article (a, an) to the sentence. But I am getting results such as these: I eat a apple. I ride an bike. What am I doing wrong?

Import random
def main():
    pronoun = ["I ", "You "]
    verb = ["kick ", "ride", "eat "]
    noun = [" ball.", " bike.", " apple.", " elephant."]
    ind_art = "an" if random.choice(noun[0]).lower() in "aeiou" else "a"

    a = random.choice(pronoun)
    b = random.choice(verb)
    c = ind_art
    d = random.choice(noun)

    print(a+b+c+d)
main()



Aucun commentaire:

Enregistrer un commentaire