15,185 Topics

Member Avatar for
Member Avatar for DustinS

import os data = map(lambda c: ord(c), file(args[0]).read(os.path.getsize(args[0]))) For one file, os.path.getsize(args[0]) returns 10456 while len(data) returns 281. After looking at different files, I realized that it always stops reading at the 0x1A character. The documentation says that in Windows, Python uses _wfopen which (for compatibility reasons) interprets 0x1A (CTRL-Z …

Member Avatar for Gribouillis
0
2K
Member Avatar for shanenin

I can't seem to see how this slice works test = (1,2,3) >>> test[::2] (1, 3) any insite would be helpful

Member Avatar for shanenin
0
1K
Member Avatar for dtripath

How to write a function for highest denomination of any card in the hand.The denominations from lowest to highest are 2, 3,4,5,6,7,8,9,10,'jack,''queen','king','ace'.For example, highestDenomination({(6,'club'),(6,'heart'),('queen','heart'),('queen','diamond'),(2,'heart')})denotes‘queen’.

Member Avatar for vegaseat
0
112
Member Avatar for s123456

spring model....i want to get the program to return the value of the period of the motion of the pendulum i have tried putting this outside the loop oldVelocity = vector(0,0,0) and this inside the loop before v: oldVelocity = m.v with print statement: if oldVelocity.y/m.v <0: print ("time = …

Member Avatar for s123456
0
406
Member Avatar for Lardmeister

This little experiment with Tkinter and pixel drawing shows some strange effects (look at line 27 comments!!!): '''tk_put_pixel.py place a pixel at pos=(x,y) with color=(r,g,b) on an image area note: one pixel might be hard to see, so create a series of pixels (line) ''' try: # Python2 import Tkinter …

0
142
Member Avatar for favoredanteater

python help on making the program accept other values? # Find the area and perimeter of a rectangle import math class Rectangle(object): """A 2D Recangle""" def __init__(self, width = 1, height = 2): self.width = width self.height = height def Perimeter(self): "Return the Perimeter of the rectangle" return (2 * …

Member Avatar for Schol-R-LEA
0
208
Member Avatar for Inshu

TypeError: 'float' object has no attribute '__getitem__' What does this mean ???

Member Avatar for Lardmeister
0
751
Member Avatar for pauldespre

Hello, I have this functions: main(), menu1(),menu2() and so on. Main function takes an input and call one of the menu() functions so ... menu1(),menu2() functions needs to be defined before the main() function. The problem appears when i want to call the main() function inside one of the menu() …

Member Avatar for TrustyTony
0
144
Member Avatar for La:)

I am trying to write a program to generate hailstone sequences for different starting values of n and have achieved this. Now however, I am trying to find the average length of the sequences and what the longest and shortest sequences are in the range(5,1000)and am not sure how to …

Member Avatar for abc0502
0
1K
Member Avatar for vegaseat

[B]Intro[/B] C is using structures to group data, mostly data that belongs together. Here we have some data that a campaign manager might keep for the volunteers. First we take a look at the C code: [code=c]#include <stdio.h> struct person { char *name; char *sex; char *slogan; }; int main(void) …

Member Avatar for georgooty
0
763
Member Avatar for zygimantelis

I creating a test program for TKinter, and getting some errors :( from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=LEFT) self.hi_there = Entry(frame, text="Hello", command=self.say_hi) self.hi_there.pack(side=LEFT) username = StringVar() name = Entry(frame, textvariable=username) name.pack(side=LEFT) print name.get() def say_hi(self): …

Member Avatar for Schol-R-LEA
0
1K
Member Avatar for barrelr0ll

Hey there, so I recently joined an online course, and the first mini-project is to create rock, paper, scissors, lizard, spock. upon testing my program it seems I've got an error in my code and I can't for the life of me figure it out, I was hoping you guys …

Member Avatar for barrelr0ll
0
92
Member Avatar for doobz

Hi, I'm in an intro to Computer Programming class, and we need to make a program that rolls 5 die, and tells you if you have any combinations (pair, 3 of a kind, 4 of a kind, 5 of a kind, and Pair+3 of a kind) My program rolls perfectly, …

Member Avatar for woooee
0
760
Member Avatar for MissAuditore

Hi, I was wondering if there is a way to click at a certain point in the figure thats made, and make python pick up those values. So I can see the value of x f.ex in the down left corner in the figure. So my question is if it …

Member Avatar for vegaseat
-1
99
Member Avatar for vegaseat

This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape.

2
4K
Member Avatar for sgeep

Hey guys, I'm in an introductory computer science class that deals with Python. We're assigned to create a dice-rolling program using Tkinter, and I have the interface pretty much down, but I'm having trouble linking it to the dice-roller. Here it is. import random import Tkinter win = Tkinter.Tk() win.title("Die …

Member Avatar for TrustyTony
0
835
Member Avatar for Inshu

I have a little problem to solve .. i have a array with x, y, z co-ordinates in it as a tuple. I am trying to find the distance between each point and sorting the points according to the min distance. Can soemone help me with the algorithm ??

Member Avatar for woooee
0
220
Member Avatar for vegaseat

There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ...

Member Avatar for rubik-pypol
3
392
Member Avatar for Inshu

def CalcCentre(data): centre = array([0,0,0]) count = 0 for p in data: centre = add(centre, array(p[:3])) count += 1 centre = dot(1./count, centre) return centre

Member Avatar for Inshu
0
112
Member Avatar for syeda amna

I am trying to run a program from python command line. I installed python on D: drive. PLZZ help me in fixing this problem.

Member Avatar for syeda amna
1
578
Member Avatar for james5050

hi i have been trying to draw a stick figure, but i don't know how to start, pls i need a help.

Member Avatar for vegaseat
0
827
Member Avatar for ashley9210

I am looking at python and I want to allow the user to click on the centre of the screen and create a circle, this is what I have. Any help will be very appricated. import from graphics * def blueCircle(): win = GraphWin("Click Here") p = win.getMouse() circle1 = …

Member Avatar for vegaseat
0
111
Member Avatar for mickeyVeliki
Member Avatar for godcr7

The difference of this program from other rock-paper-scissors from is that this program ask the computer the select the weapon most likely to beat the user,based on the user's previous choice of weapons instead of using random function. #This is a program that will allow the user to play Rock, …

Member Avatar for rhuffman8
0
867
Member Avatar for weblover

Hi, i have a 2D list in python which i'm trying to fill using 2 for loops. but the problem is when i finish the filling procedure and i print the values, i find that they are not arrangeed in the order of input. def funcdist(myarr): diffs = 0 testarr …

Member Avatar for weblover
0
368
Member Avatar for robert.montgomery.75054

Okay, I thought I had this code solved: please help me..My code is not closing out..please point me to the right direction..very newbie to python # initialization phase count = 0 totalGrade = 0.0 toContinue = "yes" while toContinue != "no": moreStudents = "y" #processing phase moreGrades = "y" while …

Member Avatar for TrustyTony
0
98
Member Avatar for rhuffman8

I want to be able to write a Python script to send a text message to a user's phone using an email client. I have tried the following code: import smtplib from email.mime.text import MIMEText msg = MIMEText('message') msg['Subject'] = 'The contents of %s' % textfile msg['From'] = 'example@mail.examplecompany.net' msg['To'] …

0
307
Member Avatar for hughesadam_87

Hi guys, This feels like something that should be possible in Python, and something that I feel like I should know how to do. Image I have a list of numbers: items=[10,20,30] Let's say I wanted iterate over them and define two new variables, a and b. a=[] b=[] for …

Member Avatar for hughesadam_87
0
177
Member Avatar for glenwill101

hello ive been working on a small project and im a bit stuck. import subprocess path = "/var/log" #i wanna be able to do something like subprocess.call("nano path") # but i noticed that using nano like that wont work because path is just a python string any help

Member Avatar for Gribouillis
0
124
Member Avatar for padton

Hi all, I am looking at neat ways of re writing this code below, especially the for loops as I would have over 50 of these statements if I did this the manual way shown below. n = 50 files = [open("files%i.txt" % i, "w") for i in range (n)] …

Member Avatar for Gribouillis
0
229

The End.