- Strength to Increase Rep
- +17
- Strength to Decrease Rep
- -4
- Upvotes Received
- 3K
- Posts with Upvotes
- 2K
- Upvoting Members
- 477
- Downvotes Received
- 104
- Posts with Downvotes
- 79
- Downvoting Members
- 75
Scientist
- Interests
- Astrophysics Sailing Hiking
- PC Specs
- Dell Inspiron 15 Windows81, Raspberry Pi Linux, MacOSX
4,305 Posted Topics
Re: Just mildly more modern ... ''' coinflip102.py flip a coin 100 times and count heads and tails ''' import random # create a 100 count list of random 'head' or 'tail' mylist = [random.choice(['head', 'tail']) for k in range(100)] print("The Number of heads was {}".format(mylist.count('head'))) print("The Number of tails was … | |
Once harm has been done, even a fool understands it. -- Homer | |
Re: Are you trying to store your data in the file path? Please read the Windows manual on file path limitations. | |
Re: [QUOTE=Freaky_Chris;609478]Its probably including the path in that case then, since the whole path C:\\..............\\whatever including the file is 305 characters long. Chris[/QUOTE]You could use os.chdir(path) to establish the working directory and then use the filename only. | |
Re: You know the hero/star can't get killed because he/she has to appear in next weeks show. | |
Re: Just finished a grilled salmon steak with a fresh garden salad and buttermilk dressing. Right now I am working on dessert, vanilla ice cream with a Kahlua chaser. | |
Re: If you been out of school for a while, it tends to be work or church! | |
Using PySide's QAbstractTableModel allows you to easily customize a widget like QTableView and make it more generic in its application. Here we use it to present solvent data in tabular form and sort each column content by simply clicking on the header. You can feed it any data as long … | |
Things don't have to be black and white all the time. Use a Windows API call to add some color to your text output. | |
The Tkinter module comes with the normal Python installation. It allows you to create Python GUI programs for Windows, Linux or Unix on the Mac. In this snippet we put a GIF image (.gif) onto a form's canvas with just a few lines of code. Most of the lines are … | |
Re: Yes, there is a devlopment of a full featured GUI Operating System written in Python under the name Unununium (wouldn't be my choice), nicknamed after the 111th chemical element 'Roentgenium', whose temporary IUPAC name until November 2004 was 'Unununium'. See: [url]http://en.wikipedia.org/wiki/Unununium_(operating_system[/url]) | |
![]() | Re: Two movies I saw in the theater, and thought they were worth seeing again. So I bought the DVDs: "Crazy Stupid Love" with Steve Carell and Lulianne Moore. "Friends With Benefits" with Mila Kunis and Justin Timberlake. |
Re: Seems to be too simple to be homework. You were almost there, you should only multply the overtime pay by 1.5. [code=python]""" output should be: Pay rate $10.00 Regular Hours 40 Overtime hours 20 Regular pay $400.00 Overtime pay $300.00 Total Pay $700.00 """ def hours(): hours = input("How many … | |
Re: If you want to concatenate (join) every two lines in your file, then you can use something simple like this ... [code=python]names = """\ Valerie Vanessa Velvet Venice Venus Verena """ # create a test file filename = "mynames.txt" fout = open(filename, "w") fout.write(names) fout.close() mod_list = [] count = … | |
For those who are afraid of lycanthropes and full moons, here is a way to figure out the phase of the moon. | |
Re: Just a little quirk in Tkinter. Since the canvas has a default border of 2 pixels simply give it a [B]bd=-2[/B] to cancel it. | |
What "Hello World" is to the console, the "Bouncing Ball" is to the Graphical User Interface. Nothing fancy, the ball is created via a call to the API function ellipse() and then bounced within the confines of the windows form. For the DEV C++ crowd: Let me know if you … | |
The printer seems to be a much ignored computer peripheral when it comes to programming. This little code snippet explores one way to send text to the default printer. It actually draws the text into an imaginary box on the paper. You can specify the upper left and lower right … | |
Re: If you have pip installed, check with ... ''' modules_pip101.py list all the installed modules ''' import pip for item in pip.get_installed_distributions(): print(item) | |
![]() | Re: Something like Lardmeister's code would be a good start of an Equation Solver as set forth in: [url]http://www.daniweb.com/forums/post159522-7.html[/url] Just make sure you keep your units of measurement correct. |
Re: You might want to check: https://www.varycode.com/converter.html | |
Re: That particular software is very early alpha at best. At this point it is very clumsy and will frustrate you thoroughly! | |
Re: From the Python manual that ships with every installation: str.strip([chars]) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. ... Python … | |
Re: I assume you are using Windows. With your knowledge in basic you should look into BCX. It programs in a modern basic and then translates to compile with a number of C or C++ compilers. I look at C is just a subset of C++, well let's say 99% of … | |
Re: Rule of thumb is that it takes about ten good C++ programmers to do what 1 good Python program can accomplish in a given time span. So, yeah there are a lot more C++ jobs out there! On could imagine that with the help of AI future computers could do … | |
Re: You might want to check PIL/pillow at: http://pillow.readthedocs.org/en/latest/ | |
Re: A true Klingon Warrior uses only machine code, keyed in on the front panel switches in raw binary. | |
Re: Judging from what he does to the inside of my mouth, that could have been my own dentist. After all, a dentist lives from the pain of others. | |
| |
Just trying to find out which of these five isprime functions is the fastest. | |
Re: Take a look at ... http://www.daniweb.com/software-development/python/threads/466346/word-jumble#post2031135 | |
This simple isprime(number) function checks if the given integer number is a prime number and returns True or False. The function makes sure that the number is a positive integer, and that 1 is not considered a prime number. To find out if an integer n is odd one can … | |
If you press any key on your keyboard, this small Tkinter GUI program will tell you which key and what type of key has been pressed. Great for applications where a simple key stroke is required. | |
Re: Play around with this, it might give you enough hints: http://www.developerfusion.com/tools/convert/csharp-to-python/ Good advice: http://stackoverflow.com/questions/683273/advice-for-c-sharp-programmer-writing-python There is also IronPython (MS endorsed) with a Python syntax that can be called from C# (4.0): http://blogs.msdn.com/b/charlie/archive/2009/10/25/hosting-ironpython-in-a-c-4-0-program.aspx | |
An example showing how to use the wx.media.MediaCtrl() widget to play MIDI, MP3, WAV, AU, AVI and MPG audio and video files. I have only tested it with Windows. If you are very ambitious, you could use a random graphics display with the sound, or tie the slider position to … | |
Re: This might be a hint: '''zg_triangle1.py using the Zelle graphics module (derived from Tkinter) http://mcsp.wartburg.edu/zelle/python/graphics.py ''' from graphics import * def drawTrianglePatch(win, colour): # polygon goes back to starting point (80, 20) triangle = Polygon(Point(80,20),Point(180,60),Point(60,220)) triangle.setFill(colour) triangle.draw(win) w = 250 h = 250 win = GraphWin("triangle stuff", w, h) colour … | |
Re: Recursive functions have a neat look, but consume much stack space, Python sets a recursion limit of 1000. Recursive functions are rather slow, a while/for loop is much faster. Here are some typical examples: def get_factorial1(n): ''' would be poor choice because of the many function calls each call has … | |
This short Python code gets the local time from the PC as a formatted string using time.strftime('%H:%M:%S'). The time string is displayed in a label using a larger font. A recursive function checks the time five times per second, and updates the time string, if it has changed. Five times … | |
Re: Maybe pySerial will do: https://pyserial.readthedocs.io/en/latest/ | |
Re: You might want to look at third party module **pandas** (it is a free download) http://pandas.pydata.org/pandas-docs/stable/tutorials.html#pandas-cookbook | |
Re: "The world is a dangerous place, not because of those who do evil, but because of those who look on and do nothing." Albert Einstein | |
Let's say you want to send a short private message to your friend, but don't want grandma to snoop around and find it. One way is to use the Python Image Library (PIL) and hide the message in a picture file's pixels. Just looking at the picture you will barely … | |
Re: The problem with the code in https://codegolf.stackexchange.com/questions/4707/outputting-ordinal-numbers-1st-2nd-3rd#answer-4712 is that the suffix for mumbers 11, 12, 13 is wrong. | |
Re: Here is another example I wrote a while ago: ''' urlretrieve_image1.py retrieve and save an image from a web page using ... urlretrieve(url[, filename[, reporthook[, data]]]) tested with Python27 and Python36 by vegaseat ''' try: # Python2 from urllib import urlretrieve except ImportError: # Python3 from urllib.request import urlretrieve # … | |
Re: Try to get the sequence of numbers into a list using a for loop. Then you can sum up the elements of the list with sum() | |
Re: Nice approach! Here is another option to do this ... ''' tk_button_toggle2.py use a list default argument to create a Tkinter toggle button ''' try: # Python2 import Tkinter as tk except ImportError: # Python3 import tkinter as tk def toggle(tog=[0]): ''' a list default argument has a fixed address … | |
Re: I could think of valid functions that perform an action, like formated printing. No need to return anything. | |
Re: Python has a nice thing called sequence **slicing**: [starting-at-index : but-less-than-index [ : step]] 'start' defaults to 0, 'end' to len(sequence), 'step' to 1 for instance s = "123456789" then s[-1:] --> 9 s[-2:] --> 89 s[-3:] --> 789 and so on, do this with a for loop in range(1, … | |
Re: Give your function an argument, in this case just an empty one. **def exit(event):** | |
This code shows how to obtain and display a GIF image from an internet website using the Tkinter GUI toolkit that comes with the Python installation. |
The End.