82.9k views
1 vote
Ask the user to input a word until the user says "no" in any possible case variation (NO, no, No, nO). Each time the user enters a word, capitalize the word and print it followed by the length of the word.

User Razib
by
7.7k points

1 Answer

3 votes

Final answer:

To achieve this, you can use a while loop that continues until the user enters 'no', regardless of the case variation. Inside the loop, you can prompt the user to enter a word and then capitalize it using the capitalize() method in Python. After capitalizing the word, you can print it along with its length using the len() function.

Step-by-step explanation:

To achieve this, you can use a while loop that continues until the user enters 'no', regardless of the case variation. Inside the loop, you can prompt the user to enter a word and then capitalize it using the capitalize() method in Python. After capitalizing the word, you can print it along with its length using the len() function.



word = input('Enter a word: ')
while word.lower() != 'no':
capitalized_word = word.capitalize()
print(capitalized_word, ' - Length:', len(capitalized_word))
word = input('Enter a word: ')



For example, if the user enters 'hello', the program will output 'Hello - Length: 5'. The loop will continue until the user enters 'no', regardless of whether it is in uppercase, lowercase, or a combination of both.

User Rafael Milewski
by
7.5k points