mercredi 21 octobre 2020

How to add an integer after a listed word in python? [duplicate]

I am trying to add a random integer after the "*bank" word from the list with a range of 10-100. Here is my code below:

import random

sentence = "Your temporary password will be *bank for now."
sentence = sentence.split()
wordBank = ["dog", "cat", "lizard", "lion", "bear"]

indexCount = 0
for word in sentence:
    if word == "*bank":
        randomWord = random.choice(wordBank)
        sentence[indexCount] = randomWord
    indexCount += 1

sentence = " ".join(sentence)
print(sentence)

So I want it to look like this: "Your temporary password will be lizard56 for now."




Aucun commentaire:

Enregistrer un commentaire