15,185 Topics
| |
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 … | |
I can't seem to see how this slice works test = (1,2,3) >>> test[::2] (1, 3) any insite would be helpful | |
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’. | |
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 = … | |
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 … | |
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 * … | |
TypeError: 'float' object has no attribute '__getitem__' What does this mean ??? | |
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() … | |
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 … | |
[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) … | |
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): … | |
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 … | |
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, … | |
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 … | |
This Python Tkinter GUI toolkit code draws a shape, and shows you when and where the mouse has been clicked within the shape. | |
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 … | |
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 ?? | |
There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit ... | |
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 | |
I am trying to run a program from python command line. I installed python on D: drive. PLZZ help me in fixing this problem. | |
hi i have been trying to draw a stick figure, but i don't know how to start, pls i need a help. | |
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 = … | |
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, … | |
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 … | |
| 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 … |
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'] … | |
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 … | |
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 | |
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)] … |
The End.