Aug-03-2018, 04:38 PM
Hi,
Please see the attached screenshot of my terminal to see what the issue is?
[Image: sorted_zpscfwnb8km.png]
When I pressed Enter on an empty line the program should end & the words entered whould be printed in an alphabetical order.
Please advise what's next? Thank you
=============================================================================================
Here's the exercise that I've been trying to do:
# Building and sorting an array. Write the program that asks us to type as many words as we want (one word per line, continuing until we just press Enter on an empty line) and then repeats the words back to us in alphabetical order. Make sure to test your program thoroughly; for example, does hitting Enter on an empty line always exit your program? Even on the first line? And the second?
# Hint: There’s a lovely array method that will give you a sorted version of an array: sorted(). Use it!
=============================================================================================
Here's my code:
Please see the attached screenshot of my terminal to see what the issue is?
[Image: sorted_zpscfwnb8km.png]
When I pressed Enter on an empty line the program should end & the words entered whould be printed in an alphabetical order.
Please advise what's next? Thank you
=============================================================================================
Here's the exercise that I've been trying to do:
# Building and sorting an array. Write the program that asks us to type as many words as we want (one word per line, continuing until we just press Enter on an empty line) and then repeats the words back to us in alphabetical order. Make sure to test your program thoroughly; for example, does hitting Enter on an empty line always exit your program? Even on the first line? And the second?
# Hint: There’s a lovely array method that will give you a sorted version of an array: sorted(). Use it!
=============================================================================================
Here's my code:
print("[System] Hi! Enter as many words as you want. One word per line until you press Enter on an empty line. This program will then repeat the words in alphabetical order. Ready?!") empty_line = 0 words_list = [] while True: word = input("Enter a word: ") words_list.append(word) if empty_line == "": print("[System] Program Ended...") empty_line = 0 words_list.append(word)
Blockchain Visionary & Aspiring Encipher/Software Developer
me = {'Python Learner' : 'Beginner\'s Level'}
http://bit.ly/JoinMeOnYouTube
me = {'Python Learner' : 'Beginner\'s Level'}
http://bit.ly/JoinMeOnYouTube