Skip to content

Instantly share code, notes, and snippets.

@Kwisses
Last active March 5, 2016 00:49
Show Gist options
  • Save Kwisses/f5b4bd5138284443e320 to your computer and use it in GitHub Desktop.
Save Kwisses/f5b4bd5138284443e320 to your computer and use it in GitHub Desktop.
[Daily Challenge #9 - Easy] - Alphabet/Numerical Orderer - r/DailyProgrammer
# ***** 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()
@Kwisses
Copy link
Author

Kwisses commented Mar 4, 2016

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