15,181 Topics
| |
| Is there a way to, instead of duplicating code, to either print the desired number of rows from a list (from user input) or print all items in the list? [CODE]print_list( input ): f = open('pickle.dat', "r") L = cPickle.load(f) f.close() for i in range( input=len(L) ): print 'L[i] = … |
I have something to share with you guys if you can help me out.. Here is an algorithm to print out a pyramid of numbers: [I][B]define totalRows to be how many rows define columnWidth to be how many characters in each column for currentRow in range 0 up to (but … | |
'''check addition''' from random import randint def checkAddition( a, b ): ans = int(raw_input("What is %d + %d ? " % (a,b))) if ans == a + b: return True else: return False def main(): x = randint(1,100) y = randint(1,100) if checkAddition(x,y): print "Correct" else: print "Incorrect" main()[B] [I]This … | |
I was wondering if it was possible to use pygments with wxPython? I want to use it on the text_ctrl widget. If it is not possible on that widget but is possible on an other please tell me... | |
A little late for April 1, but here is the secret code ... [code]searchEngineNames = [] for c in range(ord('A'), ord('Z')+1): name = chr(c)+'ing' searchEngineNames.append(name) # pick #1 print(searchEngineNames[1]) [/code] | |
i have been working on this code [code=syntax] '''Calculate the cost of fuel for a road trip''' def main(): distance = float(raw_input("Enter distance in kilometres: ")) litresPer100K = float(raw_input("Enter economy (ltr/100km): ")) pricePerLitre = float(raw_input("Enter fuel price per litre ($): ")) cost = distance / 100 * litresPer100K * pricePerLitre … | |
Hey, I have a really big file on my computer, this file only got words in it. And because the file is really big, I sure there are repeted words in there. Is there a way of deleting every single repeated word, leaving at least one? Every single word is … | |
How would one use Python as a PHP alternative? If there a hello world example somewhere? | |
Hi, just hoping someone can shed some light on the best way to read from a text file. I wish to create a program that will grab out specific words/numbers when chosen. I need to be able to extract data from different fields but also be able to determine if … | |
i am having this problem related to function implementation. my program is about sending an unread sms string to a bluetooth module and after sending the strings of sms messages it will mark the unread messages as read then move to a sms notification function that will notify me is … | |
Hello, the code I am posting sorts a pivot table but there can be only one statistic per row e.g Mean or Count. I often have multiple statistics per row e.g Mean, Mode etc... . I often have to generate multiple, long, pivot tables and to sort them manually is … | |
Let's say we have this code : [CODE]#include <iostream> #include <boost/python .hpp> using namespace boost::python; class A{ void foo (void) { std::cout << "Hello World"; } }; BOOST_PYTHON_MODULE(hello) { class_ <A> ("A") .def("foo", A::foo); }[/CODE] and I have an object of type A named MyCPPClass and I want to make … | |
This is problem part of my assesment I've done but my assesment says use a function to calculate the fuel cost and function should take 3 parameters : distance,economy(as litres per 100 kms) , and fuel price per litre. The function should return the total cost of trip. Could you … | |
hi, i have been trying to get Tkinter to play a sound, however, tkSnack has brought me to this random error which i can't emplane, but i think its something to do with my operating system, ubuntu. [code]Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.5/threading.py", line 486, … | |
hey gues i search 'replace' matrix? 123 456 789 i need in output 147 258 369 | |
Hi everyone, I know this is a very beginner inquiry, but I can't seem to figure out exactly what it is that I'm doing wrong. I'm using this tutorial: [url]http://www.sthurlow.com/python/lesson05/[/url] to build a simple calculator program. My version of Python is 3.1.2 here is my code: [code] loop = 1 … | |
Also demonstrate changing the text of the widgets label dynamically. | |
I optimized very carefully program I was producing by producing the main tight loop functions half a dozen times with various implementation styles. Also i considered amount of passing information in call hierarchy in parameters or letting functions to trust proper initialization of the global variables. I got few interesting … | |
Hi, I've had a bit of experience with perl and shell scripting. I've been reading the O'Reilly Python book and have been having a go at replicating some of our perl scripts in python (v3.1.2). I'm looking to put something together than will parse through large xml files and manipulate … | |
Hey guys, I'm new here and my question is what to use (if it exists) and possibly how to simulate a "notebook" where instead of Tabs I would like to do it with buttons (wx.Button). Being more specific, what I would like to do is to make the same functionality … | |
Hi how to kill the[B] recv [/B]or [B]recvfrom [/B]in socket connection, then there is no data and the functions recv, recvfrom is in waiting mode.?for example: [CODE] sock=socket.socket(...) sock.bind((host,port)) while True: packet,address=socket.recvfrom() print packet [/CODE] if there is no data on socket it is waiting, so how to kill it … | |
[code=syntax] import random def main(max): print "\tWelcome to 'Guess my number'!" print "\nI'm thinking of a number between 1 and 100." bestoutof = raw_input("Best out of : ") num = random.randrange(101) tries = bestoutof guess = "" while guess != num: guess = int(raw_input("Take a guess: ")) if guess > … | |
Hi, I need that my server will be in waiting mode while first packet arrived, when it happens it shoud start to receive packets until the socket.settimeout(1) function kill waiting. my code seems like that, and is working properly until settimeout() return : Traceback (most recent call last): File "C:\Documents … | |
Hi All, I read the document here with the title "Using PHP and Javascript instead of CGI" on link [url]http://python.about.com/od/cgiformswithpython/ss/phpjscgi.htm[/url] can any one elaborate it with an python code say print 10 numbers.I am confused little bit that If I write test.py file for 10 numbers How will I call … | |
I have a form in which I can input text through text boxes. How do I make these data go into the db on clicking submit. this is the code of the form in the template. What do I give in form action? [CODE]<form method="post" action="[B]what do I put here??[/B]"> … | |
I'm an extreme beginner with Python (this game is the first time I have ever seen it) so please bear with me. Creating a simple dice game. Place a bet. Three dice are rolled, if any are the same value you lose. If you win, you get double your bet. … | |
This is due within a few hours, and I am unable to spot what is causing the program to not work. Any suggestions? ["""Bounce - is a game that has a ball which increases in speed when you click on the ball. That click signals the ball to speed up, … | |
I"m trying to make a [URL="en.wikipedia.org/wiki/Sudoku"]sudoku[/URL] puzzle generator (or at least the basics of one) for my project. I'm approaching this by dividing the sudoku grid into 9 rows. Each of the rows will be represented by a list and each list will have 9 elements to represent the nine … | |
[CODE] # What exactly is the difference between: class Test: pass # and class Test2(object): pass [/CODE] | |
Let's say I have this: [CODE] class main: def add(self): print '1 + 2 = 3' [/CODE] I then want to be able to call the add function again from within itself. Like this (BUT THIS DOESNT WORK!!!) [CODE] class main: def add(self): print '1 + 2 = 3' self.add() … |
The End.