Last active
March 5, 2016 00:49
-
-
Save Kwisses/f5b4bd5138284443e320 to your computer and use it in GitHub Desktop.
[Daily Challenge #9 - Easy] - Alphabet/Numerical Orderer - r/DailyProgrammer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ***** DAILY CHALLENGE #9 - EASY ***** | |
# Write a program that will allow the user to input digits, and arrange them in numerical order. | |
# 1.234 5 40 3 | |
# for extra credit, have it also arrange strings in alphabetical order. | |
# --------------------------------------------------------------------------------------------------------------------- | |
def num_orderer(numbers): | |
"""Takes numbers in any order and sorts them numerically. | |
Args: | |
numbers: Numbers to sort numerically. | |
Return: | |
list: Contains the inputted numbers in numerical order. | |
""" | |
output = [] | |
for number in numbers.split(): | |
try: | |
output.append(int(number)) | |
except ValueError: | |
output.append(float(number)) | |
return sorted(output) | |
def alpha_orderer(words): | |
""" Takes words in any order and sorts them alphabetically. | |
Args: | |
words (str): Words to sort alphabetically. | |
Return: | |
str: Contains the words in alphabetical order. | |
""" | |
words = sorted(words.lower().split()) | |
return ' '.join(words) | |
def num_alpha_orderer(): | |
"""Runs either num_orderer(run) or alpha_orderer(run) based on what the user enters. """ | |
run = input("Enter numbers or words [ex. 5 .37; there friend]: ") | |
try: | |
print(num_orderer(run)) | |
except ValueError: | |
print(alpha_orderer(run)) | |
if __name__ == "__main__": | |
num_alpha_orderer() |
NOTE: Program only does Alphabetical order OR numerical order, not both!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Daily Challenge #9 - Easy] from the DailyProgrammer subreddit. Alphabet/Numerical Orderer. Included bonus; Arranges strings in alphabetical order.
Reference: https://www.reddit.com/r/dailyprogrammer/comments/pu1rf/2172012_challenge_9_easy/