HRS - Ask. Learn. Share Knowledge. Logo

In Computers and Technology / High School | 2025-07-08

Write a program that reads a word and prints the word in the given format. The number of stars before and after the word is equal to the length of the word.

Asked by trentvw576

Answer (1)

To solve the problem of printing a word surrounded by stars, where the number of stars before and after the word is equal to the length of the word, you can write a simple program in Python. Here is a step-by-step guide on how to create this program:

Input the Word: First, you'll need to read the word from the user. You can use Python's input() function to do this.

Determine the Length of the Word: Use the built-in function len() to find out how many characters are in the word. This will determine how many stars to print before and after the word.

Create the Star Pattern: Multiply the star character '*' by the length of the word to create a string of stars.

Print the Result: Display the stars, followed by the word, and then the stars again. Use Python's print() function to output this.


Here's how the program looks:
Step 1: Input the word from the user
word = input("Enter a word: ")
Step 2: Determine the length of the word
word_length = len(word)
Step 3: Create the star pattern
stars = '*' * word_length
Step 4: Print the result
result = stars + word + stars print(result) ;

Answered by ElijahBenjaminCarter | 2025-07-22