With the help of good folks on this list, the following Python program has been created to help a newbie choose between and amongst 11 languages, namely Java, Visual Basic, C++, C, Lisp, Delphi (Pascal), JavaScript, Python, Perl, Ruby, and Tcl... Now, I keep coming up with Python, given my preferences, but your mileage may vary... Problems I still have 1. This program works fine for me when I run it under pythonWin, but when I try to run it under IDLE, I get an error message after first prompt, "Tcl error, expected boolean got ???' Why would a program run fine under pythonwin but not under IDLE (on Win(98)) 2. It's hard to make a program look nice, input and output wise, when the inputs and outputs are so different under pythonwin vs IDLE, vs at the Python DOS shell prompt...makes me want to run under Tkinter but I still have not been able to figure that out..but there should be an acceptable way to run under command line under all IDE's?? Here is the program called ProgramLanguageFinal.py:::(its still bit of spaghetti code even though I used good code form this list' members but I probably butchered it... (with huge apologies to Jeff Epler)... print "This is a program to help give you an idea which programming languages you should consider learning." print "While there are any number of languages you might consider, this program considers only 11 of the most" print "popular ones. The program will ask you to input a ranking or weighting for a number of criteria" print "that may be of importance in choosing your next programming language." def get_list(heading, prompt): """ get_list(heading, prompt) -> list This function prompts for a list of things. The heading is printed on a line by itself, and the prompt must have a %d substitution for the number of the item within the list. """ print heading print print "(enter a blank line to end the list)" ret = [] i = 1 while 1: line = raw_input(prompt % i) if not line: break ret.append(line) i=i+1 print return ret def get_number(prompt): """ get_number(prompt) -> float This function prompts for a number. If the user enters bad input, such as "cat" or "3l", it will prompt again. """ res = None while res is None: try: res = float(raw_input(prompt)) except ValueError: pass return res options = ["Python", "Perl", "Ruby", "Tcl", "JavaScript", "Visual Basic", "Java", "C++", "C", "Lisp", "Delphi"] criteria = ["ease of learning", "ease of use", "speed of program execution", "quality of available tools", "popularity", "power & expressiveness", "cross platform?", "cost"] rankings = {} print print "Enter relative importance of criteria (higher is more important)" print for c in criteria: rankings[c] = get_number("Criterion %s: " % c) # Next, get the user to score each option on all the criteria. # Here, we index the dictionary on the pair (option, criterion). # This is similar to a two-dimensional array in other languages score = {("Python", "ease of learning"):100, ("Python", "ease of use"):100, ("Python", "speed of program execution"):10, ("Python", "quality of available tools"):70, ("Python", "popularity"):50, ("Python", "power & expressiveness"):100, ("Python", "cross platform?"):100, ("Python", "cost"):100, ("Perl", "ease of learning"):50, ("Perl", "ease of use"):90, ("Perl", "speed of program execution"):30, ("Perl", "quality of available tools"):50, ("Perl", "popularity"):75, ("Perl", "power & expressiveness"):100, ("Perl", "cross platform?"):100, ("Perl", "cost"):100, ("Ruby", "ease of learning"):50, ("Ruby", "ease of use"):100, ("Ruby", "speed of program execution"):20, ("Ruby", "quality of available tools"):20, ("Ruby", "popularity"):10, ("Ruby", "power & expressiveness"):100, ("Ruby", "cross platform?"):80, ("Ruby", "cost"):100, ("Tcl", "ease of learning"):100, ("Tcl", "ease of use"):100, ("Tcl", "speed of program execution"):10, ("Tcl", "quality of available tools"):50, ("Tcl", "popularity"):40, ("Tcl", "power & expressiveness"):10, ("Tcl", "cross platform?"):100, ("Tcl", "cost"):100, ("JavaScript", "ease of learning"):70, ("JavaScript", "ease of use"):75, ("JavaScript", "speed of program execution"):10, ("JavaScript", "quality of available tools"):50, ("JavaScript", "popularity"):100, ("JavaScript", "power & expressiveness"):40, ("JavaScript", "cross platform?"):50, ("JavaScript", "cost"):100, ("Visual Basic", "ease of learning"):50, ("Visual Basic", "ease of use"):100, ("Visual Basic", "speed of program execution"):20, ("Visual Basic", "quality of available tools"):100, ("Visual Basic", "popularity"):100, ("Visual Basic", "power & expressiveness"):50, ("Visual Basic", "cross platform?"):1, ("Visual Basic", "cost"):1, ("Java", "ease of learning"):15, ("Java", "ease of use"):50, ("Java", "speed of program execution"):50, ("Java", "quality of available tools"):100, ("Java", "popularity"):100, ("Java", "power & expressiveness"):100, ("Java", "cross platform?"):100, ("Java", "cost"):100, ("C++", "ease of learning"):10, ("C++", "ease of use"):25, ("C++", "speed of program execution"):90, ("C++", "quality of available tools"):100, ("C++", "popularity"):100, ("C++", "power & expressiveness"):100, ("C++", "cross platform?"):100, ("C++", "cost"):100, ("C", "ease of learning"):15, ("C", "ease of use"):10, ("C", "speed of program execution"):100, ("C", "quality of available tools"):100, ("C", "popularity"):100, ("C", "power & expressiveness"):100, ("C", "cross platform?"):110, ("C", "cost"):100, ("Lisp", "ease of learning"):20, ("Lisp", "ease of use"):30, ("Lisp", "speed of program execution"):70, ("Lisp", "quality of available tools"):50, ("Lisp", "popularity"):25, ("Lisp", "power & expressiveness"):110, ("Lisp", "cross platform?"):80, ("Lisp", "cost"):90, ("Delphi", "ease of learning"):50, ("Delphi", "ease of use"):110, ("Delphi", "speed of program execution"):85, ("Delphi", "quality of available tools"):100, ("Delphi", "popularity"):30, ("Delphi", "power & expressiveness"):100, ("Delphi", "cross platform?"):80, ("Delphi", "cost"):10} # Calculate the resulting score for each option. # The "result" dictionary is indexed with the names of the options. result = {} for o in options: value = 0 for c in criteria: value = value + rankings[c] * score[o, c] result[o] = value # Now, I want to take the dictionary result, and turn it into a ranked list results = result.items() # A list of tuples (key, value) results.sort(lambda x, y: -cmp(x[1], y[1])) # Sort the list using the reverse of the # "value" of the entry, so that higher # values come first print print "Results, in order from highest to lowest score" print print "%5s %s" % ("Score", "Option") # Take the pairs out of results in order, and print them out for option, result in results: print "%5s %s" % (result, option)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4