TopCarBrands = ["Toyota","Honda","Chevrolet","Ford","Mercedes-Benz","BMW","Porsche","Subaru","Nissan"]
secretword = random.choice(TopCarBrands).lower()
word = secretword
for i in range (len(word)):
word = word[0:i] "*" word[i 1:]
print (" ".join(word))
Whatever word it chooses I only want it to show once. e.g. if the word is bmw
it should be displaying ***
CodePudding user response:
Your print statement is inside the for loop. Everything that is inside of the for loop will run multiple times. Instead, move the print statement down and back out of the for loop. It should then run once. Read this article for more info. Good day!
CodePudding user response:
Per the comments, the issue is with the for loop.
Here's a simplified solution consistent with PEP8:
import random
top_car_brands = [
"Toyota", "Honda", "Chevrolet", "Ford",
"Mercedes-Benz", "BMW", "Porsche", "Subaru", "Nissan",
]
word = random.choice(top_car_brands).lower()
secret_word = "*" * len(word)
print(secret_word)