# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 5/13/2015 #Program Title: Chapter 9 Programming Excercise 2.py #(Sorted Names) #Program Description: The program prompts the user for #20 names and displays them in alphabetical order. # ------------------------------------------------------------ # Prints out sorted names def printStuff(printStr1, sortedNames): print(printStr1) for i in range(0, len(sortedNames)): print(sortedNames[i]) # prompts user for input. # takes 2 inputs, A string prompt, and the number of times it will prompt a user def promptForInput(strPrompt, numRepetition = 1): argArray = [] for i in range(0,numRepetition): argArray.append(raw_input(strPrompt + ": ")) print '{}' .format(argArray[i]) return argArray #calculates income generated def nameListSort(argInput): argInput.sort() return argInput #main driver function def main(): try: arrayArg = promptForInput("Please enter a name", 20) printStuff("Sorted Names: ",nameListSort(arrayArg)) except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter a name' main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question