- Strength to Increase Rep
- +15
- Strength to Decrease Rep
- -3
- Upvotes Received
- 584
- Posts with Upvotes
- 494
- Upvoting Members
- 185
- Downvotes Received
- 15
- Posts with Downvotes
- 15
- Downvoting Members
- 14
2,190 Posted Topics
Re: [QUOTE]Hey I did this in class the other week. This code is simple and works perfectly [code]import random Num = int(raw_input("enter number of coin flips:")) coinf = 0 h = 0 t = 0 while coinf < Num: coinf = coinf + 1 rand = random.randint(0,2) if rand == 1: … | |
Re: [QUOTE=;][/QUOTE] You can't mention drinking without some of W.C. Fields' sayings "A woman drove me to drink and I didn't even have the decency to thank her." "Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake." Not drinking related, but one of … | |
Re: You search a dictionary in this way, and note that names would be case sensitive: [CODE]def search(dict1): name2=raw_input("Enter the name whose number is to be found: ") if name2 in dict1: print name2, dict1[name] [/CODE] | |
Re: I am watching fewer shows because of the commercials. To watch any show you have to be willing to watch the commercials, or as I am doing more and more now, recording the show and fast-forwarding through the commercials. If a commercial contains Debbie Boone or insurance sold by the … | |
Re: See the last post here for the general idea [url]http://www.daniweb.com/forums/thread158680.html[/url] You want to use some variable in a while loop that you can set to false if (1) the correct word is guessed, (2) the maximum number of guesses is reached, (3) any other exit criteria. You can also use … | |
Re: Start with tkinter basics. As already stated, the Label isn't going to change, so using cget() on a label does not provide any useful data. Second, start with one get. You have 178 lines of code, and a lot of it is wrong and has to be changed. Take any … | |
Re: Use subprocess.run() https://python.land/operating-system/python-subprocess It receives a list, so it is easy to include parameters. Be sure to read about the shell=True option and decide whether it is necessary or not. | |
Re: Is this correct? from wxPython.wx import * In any case, you may have to install/re-install wxPython. | |
Re: I would guess the problem to be the columnspan or sticky parameters. You can try different combinations of those, but also might want to post to a Tkinter forum like [url=http://www.manning-sandbox.com/forum.jspa?forumID=51]Manning's[/url] as many of us use the Pmw extension which has scrollbars built in. | |
Re: Your indentation is off. Look at a basic tutorial and classes. https://wiki.python.org/moin/BeginnersGuide | |
Re: First, don't use pack() and place(). How is Tkinter to know which one to apply to the widget. Don't start multiple instances of Tk(). Same thing. How is Tkinter supposed to know which one you are referring to. Use a Toplevel() instead. This modified code does what I think you … | |
Re: The standard solution for anagrams is to sort on the letters. So 'ogd' sorted is 'dgo', and a lookup of the 'dgo' key in the dictionary yields the list ["dog", "god"]. Your code would only return whichever one of these words it found first. Also, you should not use "dict" … | |
Re: [quote]The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when divided by 4.[/quote] [code]import random # choose some random numbers and the appropriate number to pick up # so that the number of sticks = num*4+1 # no … | |
Re: First try using idle instead of Notepad. You can enter, save, and run the program from Idle. It should be under the python and then idlelib directories, and is something like Idle.py-I don't remember. That will solve the immediate problem. Your solution should work also, so it may be that … | |
Re: You should put this in a function that you can call repeatedly instead of duplicating code. | |
Re: The question itself is not clear [quote]from start to the end number (inclusive)[/quote]but the results do not include the end number [quote] range(1, 11, 2) will return a list of numbers [1,3,5,7,9][/quote]. | |
Re: Take a look at the "Starting Python" sticky at the top of this forum. There are many resources, including the Google (free) online course. | |
Re: The Xerox Palo Alto Research Center, known as Xerox PARC, developed the graphical user interface (GUI), laser printing, WYSIWYG text editors, and Ethernet. And perhaps more importantly developed object oriented programming. | |
Re: How do you determine boundaries? I would suggest that you post some stripped down code, i.e without all of the plotting, etc. as that has nothing to do with "outside boundaries". Include also an explanation of how you would like to determine what is outside the boundaries. | |
Re: Where does dollars come from, and how is it different from total_value def get_left_over_cents(pennies, nickels, dimes, quaters): total_value = get_dollars(pennies, nickels, dimes, quaters) left_over_cents = int(100 *(total_value - dollars)) | |
Re: login() is declared uner the class, even though it is not a member of the class. | |
Re: You have to grid, pack or place widgets to get them to appear http://www.effbot.org/tkinterbook/grid.htm | |
Re: >Can anyone help me? Not without knowing what you have tried. The number buttons is a simple for loop this_row = 2 this_col=0 for num in [7, 8, 9, "*", 4, 5, 6, "-", 1, 2, 3, "+"]: Button(btns_frame, text = num, fg = "black", width = 10, height = … | |
Re: You have made the classic mistake of including even numbers = testing twice as many numbers. Start out with i=3 and add two on each pass. | |
Re: The smallest time displayed is seconds. The function is called every 2/10 of a second, so the clock is not updated if the time to the second has not changed. | |
Re: So we are spending our time on simple toggles huh. This uses a list so the function has access to the previous setting. I was too lazy to create a class with an instance variable. try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk … | |
Re: > chmod u=rwx,g=rx,o=r myfile "This example uses symbolic permissions notation. The letters u, g, and o stand for "user", "group", and "other". The equals sign ("=") means "set the permissions exactly like this," and the letters "r", "w", and "x" stand for "read", "write", and "execute", respectively. The commas separate … | |
Re: A simple split will do the trick test =""" [ "this is a text and its supposed to contain every possible char." ], [ "like *.;#]§< and many more." ], [ "plus there are even newlines in it." ]""" x=test.split('[\n') for rec in x: print(rec) print("-"*20) | |
Re: Generlly, you send the button number to the function. Also, you import Tkinter twice. Which one is the program supposed to use? | |
Re: Using random.shuffle(), you can just then read them in order. http://www.tutorialspoint.com/python/number_shuffle.htm | |
Re: NameError: name 'url' is not defined There is no variable named 'url' in code posted above. | |
Re: Everything regarding the menu is usually in the same function def displayMenu(): print('Enter 1 to convert a string to uppercase:') print('Enter 2 to convert a string to lowercase:') print('Enter 3 to count the number of words in a string:') print('Enter 4 to count the number of vowels in a string:') … | |
Re: The error message doesn't make any sense as it only references line 3 > Traceback (most recent call last): File "<stdin>", line 3, in <module> IOError: [Errno 36] File name too long: '\xef\xbb\xbf<!DOCTYPE html PUBLIC "... which is from bs4 import BeautifulSoup Is BeautifulSoup installed correctly? | |
Re: Have BClass write to a separate file and combine them when the threads have finished. You could also use a thread safe SQL server, like MariaDB/MySql, but not SQLite. | |
Re: `if not read_file:`This statement is executed when bytes1 is **found** at the beginning of the file, offset/read_file==0). Use instead with open("foundhex.txt", "a") as found1: while True: read_file = bytearray(binaryfile.read(1024)) if len(read_file): find_bytes1 = read_file.find(bytes1, 0) if fine_bytes1 != -1: found1.write("Found 41646F626520 at : " + str(find_bytes1) + "\n") else: break … | |
Re: Please don't post code without any testing it. | |
Re: From the kids: Where do you find a turkey with no legs. Right where you left it. | |
Re: Use partial to pass something to the function, and the function will do something based on the value. This example prints what was passed to the function. Note that the Python Style Guide suggests function names should be lower case letters and underscores https://www.python.org/dev/peps/pep-0008/ root = tkinter.Tk() root.geometry("200x300") ##buttons=range(10) button_list=[] … | |
Re: You have two root=Tk() statements which Tkinter does not like. Also you don't have a mainloop(). And I have no idea what you want to do or why this program was posted here. | |
Re: Add a print so you know what is going on and where the problem is occurring. for ch in name: print("\nbefore", ch, total) total = ord(ch) + total - 96 print("after", ch, total) | |
Re: k is a dictionary value for the Albert Einstien key `self.grades[name]` so you are trying to sum/add a dictionary `total+=sum(k)`. I would suggest that you print "grades" so you at least know what it contains. | |
Re: You SQL query is wrong. It should be obvious that SQL can not know which field in the record to update. See "Parameterized queries" at http://zetcode.com/db/sqlitepythontutorial/ | |
Re: The following works fine on my machine. Perhaps you should submit some of the data in the file as it may be corrupted. Also, has_key is being replaced with "in".[CODE]f = ["PUT key1 value1A", \ "Junk key1 value1", \ "PUT key1 value1B", \ "PUT key2 value2", \ "PUT key1 value1C" … | |
Re: Variables created in a function are garbage collected when the function exits so you have to return them to keep a variable. Any tutorial that explains functions covers this https://wiki.python.org/moin/BeginnersGuide/NonProgrammers | |
Re: You don't need the lambdas. You are executing the function (parens follow function name) so that requires a lambda. Just pass the function reference. self.bind('<Enter>', self._label_enter) ## no parens ## and then def _label_enter(event=None): | |
Re: This code works around using different names for the same variable, and using the same name for a function and a variable. You still have problems with your logic though but hopefully if will get you started in the right direction. [CODE]#THIS PART IS NOT THE CODE ITSELF THESE ARE … | |
Re: Try pexpect [URL]http://www.noah.org/wiki/Pexpect[/URL] or subprocess pipes----->Doug Hellmann's intro [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url] | |
Re: Try it with the complete path name. [CODE]reader = csv.reader(open("/path/to/mesaure.csv", "rb"))[/CODE] [QUOTE]After running the file on a Terminal I get the results I want but is no working when running the same file, measured.py, on the editor.[/QUOTE]This is too vague to comment on. What does "not working" mean? |
The End.