Issue
This is what I have so far and I'm stuck.
user_input = float(input('Welcome to the Amazing Word Program; how many words will you enter?'))
my_list=[]
word = input('Enter word:')
while word != '':
my_list.append(word)
word = input('Enter word:')
The point of my code is to use while loops. We are supposed to print an end result of the users entered words and the letter count of each word.
Here is the result of my program:
Welcome to the Amazing Word Program; how many words will you enter? 4
Enter word: apple
Enter word: orange
Enter word: strawberries
Enter word: kiwi
Enter word:
After the user entered 4 words, what is also supposed to print out is the letter count of each word.
Here is a complete example:
Welcome to the Amazing Word Program How many words will you enter? 4 Enter word: Python
Enter word: used
Enter word: for
Enter word: programming
Word: Python Length: 6
Word: Python Length: 4
Word: Python Length: 3
Word: Python Length: 11
I'm a first year college student and at the moment, while loops do seem difficult, so I apologize if this seems like an easy code to write.
How can I use while loops to print out the length of each word, no matter how many words the user entered?
PYTHON
Solution
You need to print out your input. Also you don't actually need to save your words to a list unless you are doing something with the list afterwards. In this case you are just printing the input so you can just remove the list operations entirely.
As for the length, Python has a 'len()' function that returns the length of a given input.
print('Welcome to the Amazing Word Program')
word = input('Enter word:')
while word != '':
print("Word:", word, "Length:", len(word))
word = input('Enter word:')
Answered By - QuantumMecha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.