4,305 Posted Topics

Member Avatar for FarrisFahad
Member Avatar for vegaseat
0
351
Member Avatar for vegaseat

Just in time for the season, a star. (Playing with my grandson on the Raspberry Pi computer)

Member Avatar for sneekula
1
5K
Member Avatar for Slavi

I usually keep Python2 and Python3 on my Windows machine and you can do the same on a Linux computer. On Windows the trick is to tell your IDE which version to use. On Linux you can use the shebang line. My $35 Raspberry Pi computer (Linux) came with both …

Member Avatar for HiHe
1
289
Member Avatar for HiHe

Another option ... # remove_line_numbers102.py # copied from # http://personal.denison.edu/~krone/cs173/files/PythontoC++.pdf # page 11 s = ''' 1 #include <iostream> 2 using namespace std; 3 4 int gcd(int u, int v) { 5 int r; 6 while (v != 0) { 7 r = u % v; // compute remainder 8 …

Member Avatar for vegaseat
0
1K
Member Avatar for MasterChat
Member Avatar for sweetsmile
0
184
Member Avatar for Chem_1
Re: IDE

See http://www.ninja-ide.org/ and http://idlex.sourceforge.net/ My criteria for a good IDE is how it handles input() ... # input test (use raw_input() for Python2) name = input("Enter your name") print(name)

Member Avatar for sneekula
0
679
Member Avatar for PCSAWICK829

See also ... http://www.raspberrypi.org/help/what-is-a-raspberry-pi/ http://www.raspberrypi.org/help/faqs/ Note: The Raspberry Pi computer module runs on Linux Debian and does come with python and pygame. It also comes with a bunch of addressable IO pins, not bad for $35.

Member Avatar for sneekula
0
2K
Member Avatar for vegaseat

Once you are on the internet, you have to come up with passwords. After a while it will be difficult to remember those passwords. You could write them down somewhere, but the wrong person could find them. Why not have Python help you to come up with a logical password …

Member Avatar for Gribouillis
1
436
Member Avatar for MasterChat
Member Avatar for vegaseat
0
258
Member Avatar for stan3688

If your scores don't exceed the line width, then you can use this simple barchart ... def h_bar(mylist): ''' a simple horizontal bar chart ''' for item in mylist: print('-' * item) scores = [2, 4, 7, 11, 25, 45, 33, 24] h_bar(scores) ''' result ... -- ---- ------- ----------- …

Member Avatar for Gribouillis
0
239
Member Avatar for ~s.o.s~

Sad news indeed, rest in peace Melvin! Looking at his age, I should rename myself the "More Ancient Dragon"

Member Avatar for CodyOebel
2
792
Member Avatar for MasterChat
Member Avatar for ZeroEddy

Here is an example ... ''' pg_mouseposition1.py show mouse position with module pygame to see a list of event constants use: import pygame.constants help(pygame.constants) ''' import pygame as pg # create a 640x400 window/screen screen = pg.display.set_mode((640, 400)) screen.fill((255, 0, 0)) # red running = True while running: event = …

Member Avatar for ZeroEddy
0
414
Member Avatar for Slavi

Use of `if __name__ == '__main__':` # use it for testing function1() # allows the program to run or be an importable module # __main__ is the namespace of the current program # if a module is imported the namespace changes to the name of the module def function1(): pass …

Member Avatar for vegaseat
0
240
Member Avatar for har58

I haven't worked with py2exe for a while, but try this ... from distutils.core import setup import py2exe import lxml import gzip import requests import sys sys.argv.append("py2exe") sys.argv.append("-q") setup( console=['Ty.py'], options={ 'py2exe': {'includes': ['lxml.html', 'lxml._elementpath', 'lxml.etree','gzip','requests']}, } )

Member Avatar for vegaseat
0
1K
Member Avatar for vegaseat

This snippets shows how to have fun replacing multiple words in a text. The target words and the replacement words form key:value pairs in a dictionary. The search and replacement is done using Python's regular expression module re. The code also gives an example of a function within a function.

Member Avatar for Gribouillis
0
20K
Member Avatar for MasterChat

I can not remember the last time I sent out a handwritten letter. However, I do sent birthday cards with money in them to my nieces, nephews and grandchildren.

Member Avatar for MasterChat
0
172
Member Avatar for ram_10

import os.path directory = r"C:\Python27\mystuff" # Windows filename = "New.txt" path = os.path.join(directory, filename) # test print(path) # result --> C:\Python27\mystuff\New.txt # then ... with open(path, 'r') as fin: text = fin.read() Note: Windows allows you to replace \ with / in the directory string

Member Avatar for vegaseat
0
458
Member Avatar for ram_10

In general ... mydict = { 'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a', 'o':'b', 'p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'A':'N', 'B':'O', 'C':'P', 'D':'Q', 'E':'R', 'F':'S', 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A', 'O':'B', 'P':'C', 'Q':'D', 'R':'E', …

Member Avatar for vegaseat
0
251
Member Avatar for iamsupreeth

Check ... https://www.daniweb.com/software-development/python/code/488871/year-combobox-python-tkinter

Member Avatar for vegaseat
0
164
Member Avatar for vegaseat

An example how to use Tkinter's OptionMenu() as a combobox to allow one year to be selected from an option list of let's say the past 15 years.

2
1K
Member Avatar for matrixdevuk

You need to use at least Python version 3.4 ... ''' enum_test101.py module enum is new in Python34 see: http://legacy.python.org/dev/peps/pep-0435/ ''' from enum import Enum class Colour(Enum): WHITE = (255,255,255) BLACK = (0,0,0) RED = (215,45,45) BLUE = (45,87,214) YELLOW = (230,223,48) GREEN = (45,194,64) print(Colour.BLACK.value) # (0, 0, 0)

Member Avatar for matrixdevuk
0
353
Member Avatar for Johnny Blaz
Member Avatar for ram_10

Could be as simple as this ... def generate_n_chars(n, ch): return ch * n # test ch = 'z' n = 10 print(generate_n_chars(n, ch)) # result --> zzzzzzzzzz

Member Avatar for ram_10
0
425
Member Avatar for tmcclure57

Here we go ... ''' tk_button_run_hello.py run an external Python program via a tkinter button tested with Python3 ''' # replace tkinter with Tkinter in Python2 import tkinter as tk def run_hello(): execfile("hello.py") root = tk.Tk() btn = tk.Button(root, text="Run program Hello", command=run_hello) btn.pack() root.mainloop() Here is hello.py ... ''' …

Member Avatar for vegaseat
0
132
Member Avatar for ram_10

Another option ... s = "abcdefg" for ix, c in enumerate(s): pass length = ix + 1 print(length)

Member Avatar for vegaseat
0
194
Member Avatar for Reverend Jim

Oh yes, it is necessary for the NSA to know how much fibre you are getting in your diet. With the cost of the affordable care act going up, the government needs to know that you are living healthy. Also, eating a Middle Eastern diet would make you a potential …

Member Avatar for vegaseat
0
458
Member Avatar for COKEDUDE

See also `__STDC_VERSION__` ... http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html

Member Avatar for vegaseat
0
193
Member Avatar for roxie148

I am partial to Dell, usually get them at Best Buy. The only problem is that most notebooks/laptops come with Wndows 8.1 that can be frustrating to the user.

Member Avatar for stultuske
0
253
Member Avatar for vegaseat

For those of you who are inquisitive, here is a little Python program to approximate the value of pi to 77 digits. You can easily go further, just change the value n in range(n+1).

Member Avatar for sneekula
0
3K
Member Avatar for nwillis1
Member Avatar for nwillis1
-1
100
Member Avatar for YorkshireSpud

I like Python because you can be very innovative and quick when solving problems. My advice, stick with the newer Python3 version. Since the internet is full of Python2 examples, learn to recognize the older syntax and change it. If I remember it correctly, C# (Csharp) was Microsoft's answer to …

Member Avatar for vegaseat
0
281
Member Avatar for MasterChat
Member Avatar for MasterChat
1
409
Member Avatar for RikTelner

Maybe you should start with one of those remote controlled quatro-copter/camera combinations that are the rage right now. At least the first 10 km of space are yours to explore. Once you get into military airspace all bets are off!

Member Avatar for RikTelner
0
178
Member Avatar for vegaseat

This snippet shows you how to animate a dice roll with the Tkinter GUI, useful for many games that require a dice to give a random number from 1 to 6. An interesting use of Tkinter's grid(), grid_forget() and after() functions.

Member Avatar for Jake_6
0
4K
Member Avatar for Johnny Blaz
Member Avatar for Florian_2

Use a copy of image im2 = im.copy() Then in the loop try ... im2.putpixel((x, H-y-1),(p[0], p[1], p[2]))

Member Avatar for vegaseat
0
785
Member Avatar for misi

Another way to look at this ... ''' mpm_stuff.py comparing Python module mpmath result to C 64bit double results ''' from mpmath import * # convert to mpmath float x = mpf(65536) # set precision mp.dps = 16 print("Factorial of 65536:") print(fac(x)) print("5.162948523097533e+287193 (C)") print("65536 to the Power of 65536:") …

Member Avatar for vegaseat
0
210
Member Avatar for chloe.baee

If you teach science, let your students know what a scientist does.

Member Avatar for Agilemind
0
429
Member Avatar for ddanbe

Transferring files under Windows7 was a lot nicer than under Windows8. If Windows10 adds another "improvement", I have to think Linux.

Member Avatar for ZZucker
1
407
Member Avatar for woooee
Member Avatar for ncassambai

At your level it would be easier to time the seconds it takes to answer all the questions ... import random from datetime import datetime as dt correct = 0 incorrect = 0 name = input("Enter your name: ") start = dt.now() for i in range(10): number1 = random.randint(1,10) number2 …

Member Avatar for woooee
0
144
Member Avatar for COKEDUDE

You can follow this guide ... http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Variable_Names To me the underline connector is most readable.

Member Avatar for vegaseat
0
278
Member Avatar for Diellza

You need to create a random list for the bucket_sort argument lst ... import time import random #BUCKET SORT (up to 30) def bucket_sort(lst): bucket, bucket1, bucket2 = [], [], [] #The three empty buckets #Populating the buckets with the list elements for i in range(len(lst)): if lst[i] in range(11): …

Member Avatar for vegaseat
0
449
Member Avatar for McLaren

I can not imagine working in one of those open office spaces. There are simply too many distractions to think properly.

Member Avatar for sneekula
0
276
Member Avatar for Diellza

Your problem is in function gen(), the list comprehension should be ... def gen(number, b=100000): return [random.randint(0, b) for x in xrange(number)]

Member Avatar for Diellza
0
246
Member Avatar for 4m1nh4j1
Member Avatar for Xantipius

French in turn originates from Latin and old Gallic languages. "It's all Greek to me!"

Member Avatar for ddanbe
1
455
Member Avatar for Warrens80

Snow, deer and mountains make a Jeep 4x4 about the best thing to drive.

Member Avatar for Slavi
1
398
Member Avatar for Ed_3

The End.