2,190 Posted Topics
Re: First, when you call isprime() on the last line, you have to pass a number to test to the function, and you have to receive the result. Then you want to print out the result. As far as error messages, while testing, put some print statements in the body of … | |
Re: You can also use: [code]if score < 60: grade="F" elif score < 70: grade="D" elif score < 80: grade="C" elif score < 90: grade="B" elif score < 101: grade="A" else: print score, "is bogus"[/code]but as stated earlier, it depends on what makes sense to you. i.e. what the outline is. … | |
Re: Code something up and try it for yourself. If you get an error message then post the code here for some help. | |
Re: Also, you might subprocess instead. From the Python docs: "The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes." [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: Sourceforge seems to have a few possibilities like Forum Handler. You'll have to see what works for you. [URL]http://sourceforge.net/search/?words=python+forum&type_of_search=soft&pmode=0&inex=1&sortselect=trove__160®istration_date__0=&trove__225=456&trove__274=369&trove__160=178&trove__199=426&trove__13=14&trove__1=534&trove__6=7&trove__496=499&newfilter=Apply[/URL] | |
Re: Look through the projects for beginner thread. This or something similiar is sure to be there. | |
Re: [quote=jliu66;455786]But you can see there is no function in last line of code at all: SizeDiffE(k) = j[/quote] Try a print type(SizeDiffE) to see what it is. Also, if SizeDiffE(k) is not passing 'k' to the function SizeDiffE() then what is it doing. If it is a tuple, then it … | |
Re: [QUOTE]How can I sort it by any columns?[/QUOTE]There is a way to do this using a function, but you will have to at least __try__ to do it yourself first and then post the code here. I hope you understand that it is considered rude to "place your code order" … | |
Re: First off, Python doesn't really have arrays unless you include some of the add on packages. Python uses lists, so I would suggest that you take a look at lists. Combining is a simple matter. You can iterate through the lists with a for loop, creating a new list with … | |
Re: set.Set has nothing named elems. Beyond that it is hard to say. Post a question to the author at ActiveState, or e-mail them directly if there is an address. Also, post some code with what it is you are trying to do so someone can come up with something that … | |
Re: Look at the line following elif status == 0.3: And why do you have if/elif? Why not just print the value? | |
Re: It would be better to use an existing tool like Metakit or SQLite. This pages show how it would be done with Metakit [url]http://www.equi4.com/metakit/python.html[/url] | |
Re: [QUOTE=Ene Uran;439119]This is such an easy problem, I suggest you really try to understand it![/QUOTE] Also, a Google for "fibonacci python" has everything anyone could want. These posters are too lazy to ever make it as a programmer. | |
Re: Try append instead of add. Any tutorial or on-line book can help you with lists and how to add/append items. | |
Re: [quote=rjmiller;430827] 1 hydrogen H 1.0079 [code] if len(parts) == 4: print float.parts[4] else print 0 '%s does not have a well defined atomic weight.' % s(parts[3])[/code][/quote]The elements in a list are numbered from 0 to length, so your list is [0]-->[3]. Since you didn't ask any questions, I have to … | |
Re: [quote=grahhh;429382]This is a simplification of what the data looks like (hundreds of lines like this): [two spaces]6.0730000e+003[tab][one space]-9.2027000e+004[tab][two spaces]7.8891354e+01[tab]\r\n[/quote]string.split() treats all whites space (space, tab, newline) the same s=" 6.0730000e+003\t -9.2027000e+004\t 7.8891354e+01\t\r\n" print s.split() ['6.0730000e+003', '-9.2027000e+004', '7.8891354e+01'] | |
Re: >>> a=b="test" >>> print a test >>> print b test >>> id(a) 3084724384L >>> id(b) 3084724384L Or convert the string to a list and then back to a string when you are finished. | |
Re: [URL]http://www.python-eggs.org/[/URL] has links to other sites organized by type. For code examples google activestate.com and faqts.com | |
Re: I was just thinking about this myself and came up with ClientForm, but haven't tried it yet. [url]http://wwwsearch.sourceforge.net/ClientForm/[/url] | |
Re: It is easiest to write the data to a file, close it, and then call lpr using os.system() providing you want plain text. Anything more and you have to format it. Postscript is the easiest way to format output. | |
Re: See this quote on the main page " We only give homework help to those who show effort" | |
Re: If I enter any pin number, the program will accept it because it is > 1000 or < 9999[code]#Checks if pin is within range of 1000 to 9999 valid = 0 while not valid : if (pin > 999) and (pin < 10000) : print "Pin accepted" if pin== x: … | |
Re: Also has a video [url]http://learnpython.pbwiki.com/HowToStart[/url] | |
Re: Try a="itself ‘a parody’." | |
Re: You might want to try [code] import string file_pointer= open('wordlist.txt', 'U') dictList = file_pointer.readlines() file_pointer.close() x = 0 newDict = '' stop = len(dictList) while x < stop: ## you could also use "for each_rec in dictList :" [/code] | |
Re: [quote=Jergosh;307508]each plugin .py file is executed (via execfile()) by the PluginManager[/quote] I am not 100% sure what you are doing, but wouldn't you want the PluginManager to be an inherited class. It should also have methods to keep track of all plugins created, which "self.Plugins[newplugin.name] = newplugin" should provide, if … | |
Re: If you want to find file date, stats = os.stat( filename ) print time.ctime( stats[8] ) prints 'Tue Dec 26 14:28:16 2006' string.split, etc. yields the month, although I think you should also take the year into account. | |
Re: If you just want to download, you can use wget with the --user and --password options with a frontend to call it at specific times. I don't know if that will solve the problem, but it does have a resume option, so you at least won't have to start over … | |
![]() | Re: This will print your PYTHONPATH. If the path you want is not listed, and it shouldn't be because your program isn't found, then you have to use sys.path.append to add it.[code] import sys path_list= sys.path for eachPath in path_list : print eachPath[/code] ![]() |
Re: I like your solution, and I don't think there is any other way to handle the ace problem[quote]but was informed by one of my students that I put in a poker-like betting system instead of the blackjack betting system[/quote]They always know more than we do. Viva la future. | |
Re: [quote=goms;302388] import win32API.client ImportError: No module named win32API.client[/quote]I use Linux, but I think you would want to import win32API, without '.client' although I'm not sure. If that fails, search for win32API on you system. It is likely that you have to append the path to PYTHONPATH using sys.path.append( some_path_name). EDIT: … | |
Re: [quote]... one of the while loops has an eternally unfulfilled condition.[/quote] This is the only thing that could cause this problem (so of course it's something else). Add a separate counter to each while loop and exit after max cycles. [code]ctr_1 = 0 while True : ctr_1 += 1 if … | |
Re: Instead of self.hours=credits. do you want to total them self hours += credits | |
Re: [QUOTE=sneekula;299775]How does Python handle mixed type lists to get such a result?[/QUOTE] Pretty much, all pc's use ascii encoding and sort in "ascii order", see [url]http://www.asciitable.com/[/url] | |
Re: [code]def main(): grade_str = raw_input("Enter gradepoint or (Enter to quit): ") if grade_str == "": break try: grade = float(grade_str) except ValueError: print "Error, use floating point number" return[/code]You want the "try :" statement as the first statement after "while 1:". That will give you an error message if a … | |
Re: [quote] File "C:\Python23\p2sort.py", line 40, in main if dfield == gpa: NameError: global name 'gpa' is not defined[/quote] I think you want "gpa" in quotes. if dfield == "gpa": A simple menu would be easier for the user, with 1=gpa, etc. In any case, you should have a list of … | |
Re: [QUOTE]Another error that happens is if the program is expecting a number and gets a letter.[/QUOTE][CODE]if input_string.isdigit(): do_something() else : print "Enter a number"[/CODE][QUOTE]if someone hits enter by mistake without entering anything, it errors, is there a way to avoid that?[/QUOTE][CODE]if (input_string) and len(input_string) > 0 : ## -----or try … | |
Re: Not sure if this is what you want to do or not, but try replacing [CODE] else: value = fib(n-1)+fib(n-2) ## with else: value = fib(n-1)[/CODE]You might also want to use a list to store the two fib numbers, since fibs are not sequential. Again, not sure what you are … | |
Re: [QUOTE] I cannot get my return of the Fibonacci number to work properly and when I ran this program with fib(10) it ran forever.[/QUOTE]'Ran forever' because you are calculating using the same number over and over. Look at your output. If you want to compute a fib you first have … | |
Re: You can use type() [code] x = random.randint(0,10) y = random.randint(0,10) li = [1,2] li2 = [x,y] test_list = [] if every_value of li2 is in li: if type(every_value) == type(test_list) : do this [/code]Note that 'of li2 is in li' will compare entire list to list, not each element, … |
The End.