samedi 5 novembre 2022

Python3, Random entries into a format string problem

I am making a program that generates the phrase, "The enemy of my friend is my enemy!" actually, I want this phrase to print out a random permutation of (Friend/Enemy) in each place every time it is re-ran.

so far I got the code to print out the same word 3 times in each, but not a different word in each place.

I couldn't get python to access each string individually from a list. Any ideas?

Thanks!

`

import random

en = 'Enemy'
fr = 'Friend'
words = en, fr

for word in words:
    sentence = f"The {word} of my {word} is my {word}!"
    print(sentence)

`




Aucun commentaire:

Enregistrer un commentaire