- Strength to Increase Rep
- +2
- Strength to Decrease Rep
- -0
- Upvotes Received
- 15
- Posts with Upvotes
- 14
- Upvoting Members
- 7
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 1
Science and Math Researcher (For Fun)
- Interests
- Rock, Science, Math, History, Economics
Re: This can be accomplised in one line using "lambda" and a one line "if/else" statement: `t_btn = tk.Button(root, text="True", width=12, command = lambda: t_btn.config(text="False") if t_btn.config('text')[-1] == 'True' else t_btn.config(text="True"))` | |
Re: First off, ignore my non-PEP-8 compliant coding, and just change them as needed. I left your code intact up to and including line 13, `total_value = get_total(pennies, nickels, dimes, quarters)` I eliminated your get dollars and getcents functions, as you can get those with one short line using `divmod`. `divmod` … | |
Re: Great stuff. I did't know that that capability was availble. Thanks. | |
Re: I had the same problem as you when I eliminated the semicolons--The object kept moving wildly around. Turns out that one must be judicious in removing the semicolons on line 23, as the result may not--mine didn't--indent properly. Once I preserved the proper indentation, all was well. | |
Re: I think the redesign of the site is a disaster. I thought that the first moringing it was up, and still do. Seems it was designed by someone that does not know, and/or understand the Web desing mantra of "Don't make them think." Site navigation here has sort of become … | |
Re: Great stuff thanks. I'm running 2.7 I had to change `quit()` on line 54 to: root.destroy() sys.exit() Otherwise my run of it would hang on cancel. Also in 2.7, I had to change some of the imports, and line 72, because several Tkinter modules have been change in 3.+ from … | |
I found that one can use dictionaries to hold Tkinter widget config and display parameters. This then permits one to have these dictionaries elsewhere in the code for easy modification instead of buried within the code for each widget. I particularly like to place these dictionaries toward the top of … | |
I have been learning NumPy arrays/matrices in Python. As I worked, I found that I desired a more readable form of 3d matrices. So I figured that writing one would be a good goal and learning exercise. The goal was to create a function that would print 3d NumPy matrices … | |
Re: Very nice. Thanks. I would, will, add a reciprocal key. | |
Note: In Python 2.7 use: `from __future__ import print_function` to use examples. In Python, by default, the key and value pairs in a dictionary are stored as hashes, therefore dictionaries do not retain the order in which values were added, and cannot be ordered. v_Dict ={} v_Dict["First"] = 99 v_Dict["Second"] … | |
Re: Good stuff, and ideas. Thanks. I am not a "spammer," but I do eat Spam. Does that make me a spammee? | |
Re: Use an initialized list variable, `ListTotal = []` then use append in your loop: `ListTotal.append(int(i))` to put each newly converted int number in the list. Instead of running another loop to sum things, do it as you go with another initialized variable: `v_Sum = 0` and then after the list … | |
Re: Coincidentally how to do a multi-input was rattling around my head for the past two weeks. Tonight, I click on turtorials for S & G, and bam!, there's the answer. Thanks. | |
Needed a func to convert base 2 into 10, and back. Found the referenced code in this func for moving between three bases, and generalized it to between bases 2 and 62, and all in between. Upconvert a number, then down convert, then upconvert again. Go wild, have fun. | |
In my quest to learn more regarding programming in Python, I "dissect" a lot of other people's code. While doing this, or writing my own code, I end up with 10's of debug print lines. Things like this: if v_Debug == 1: print("DEBUG - ".format()) # DEBUG If I decide … | |
I, and many others, desired a "switch" keyword in Python. For me it was to a desire to make some of my code more compact and readable, as I often have many user selected options for the code to weed through. So I set off on a journey to figure … | |
Re: I know that you are still learning, but you may want to get into the habit of using more descriptive variables. Doing so will make your life much easier later when debugging or months from now when you are trying to figure out how something you wrote works. I know, … | |
I needed a random color selector. I found one [here](http://peepspower.com/python-script-to-generate-random-css-colors). I rewrote it to make it more general purpose. "f_GenRandomColor" is the picker. The output is in list form, which should make it suitable for most general applications. "f_HTMLRandomColorChart" is just a way to create an HTML table to test … | |
Re: For an IDE, I use PyScripter for my Python coding. Just the right mix of highlighting, etc. that I need for my rather basic programs/script. I like the ability to add keyboard shortcuts for code templates. So, as I learn how to do certain things, I add that code as … | |
When recursion won't do, then memoizaton will. | |
Allows multiple entries using raw_input. I often have to enter multiple items in my Python programs. I desired an easier way than using a loop(s). Today I discovered a way, and with a few mods made it happen. | |
Recently I started teaching teens programming. I use Python for them. An adult approached me and asked if I would teach her. The problem is that she's in her 40s, and hasn't had to think logically or algorithmically since high school, if ever. Scratch/Snap is too basic, and Python, in … | |
Re: Looks great, but having followed Micro$oft since the late 80s, I quiver at any mention of them and anything good, or that I love, in the same sentence. And I do love Python. I have seen M$ buy or get involved with technologies or products only to see those technologies … | |
I just love generators in Python. One of the cool things I found out from [this](http://nedbatchelder.com/text/iter.html) site was that one could send in a value when calling on an active generator. To do so one uses the send() method and a yield like so: "x = yield". The send with … | |
Re: Great stuff. I went through it and saved it for future reference. Great cheat sheet. Thanks | |
As a result of my research in number theory I find that I often need to break a number down into its numerical parts while stepping through one divisor to another. I call this process "break factoring," as I am just breaking a number down into parts, and not necessarily … | |
Also because of my work in number theory, I often need to have the root floor and root ceing of a number. This is my function for computing those two numbers from a target number. | |
I do a lot of work in number theory, especially with factors. I often need just the two middle factors from a very long factor list/result, so I created a function that takes a factor list and returns just the middle two, or one, factors. Nothing earth shattering, but I … | |
Instead of using letters as substitutes for playing card suits, I came up with a way to use unicodes to produce the common suits. The following creates the coded needed, makes the deck, and then prints the deck. The printing was the hard part. Is 2.7, and should be 3.0+ … | |
My code and funcs for printing to columns in 2.7 and 3.0+ using print(). I had to relearn column formatting as I moved to using the print() function, and so the follwing is a result. Inspired and partially copied from discussion on [StackOverflow](https://stackoverflow.com/questions/9989334/create-nice-column-output-in-python) def main(): # Main Code v_Data = … |