- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 6
- Posts with Upvotes
- 6
- Upvoting Members
- 4
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
46 Posted Topics
Re: I'm actually fairly new with Python, but I have some experience with other languages, and in alot of languages, they won't keep floats exactly as we want them too. Try multiplying everything by 100 until you need to display it to the user. So 50 cents would be 50 instead … | |
Re: Without going into the full process, I would probably read every line into a list and break each line down into a list of characters. That way, you have a list such that list[2][3] refers to 2 rows down and 3 characters over in the maze. I would also have … | |
Is it possible to have a function run at the beginning of every function of a class without explicitly writing it? I'm going to have a class with 20 or so methods, and though I can just copy and paste, I was wondering if there was an easier way to … | |
Re: I'm not quite sure what you are doing with the whole of the code, but I get what you want. Let's say you have three different lines of code, and a random number between 1 and 3. If it's 1, you execute the first line, if it's 2, you execute … | |
I'm working on a game in pygame, and I decided I wanted to make it load flash files for the characters in battle so I could animate them in flash. Is there a module that will allow for easy displaying of multiple flash files, and also for skipping to certain … | |
Re: I would use a virtual machine with windows and python on it and install the win32 module. There's no good way to simply replace it. | |
Re: When printing multiple things, seperate them with a comma. For instance: [code] distance = 15 print "The distance is", distance #Output: The distance is 15 [/code] However, there's a better was to do it: [code] distance = 2.873430192 print "The distance is %.2f miles." % distance #Output: The distance is … | |
Re: You pretty much had it there. Just use some string formatting. [code] def displayDate(day, month, year): m = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] return "%d %s %d" % (day, m[month-1], year) [/code] | |
Re: So you want 3 slots on the body where you can have armor, and some armor can take up more than one of those slots, and you want to have armor equipped only in the slot it should go in if it can? If that's the case, the character could … | |
Re: I'm really surprised no one's helped you, yet. You did alot of the work already. For the first one, first blank, you're trying to get every character of the word except the last one, since the last one is punctuation. [ICODE]-1[/ICODE] will do just that. For the second blank, I … | |
Re: Being as general as possible, you could pass a list to a function, and if there's a new item not in that list, it's appended to it. If it's already in the list, then you can return true for repeats or w/e. [code] def doesListHaveRepeats(baseList, whereAt=0, tempList=[]): if whereAt == … | |
Re: [code] def removePostfix(argWord): leaves = "s", "es", "ed", "er", "ly", "ing" for leaf in leaves: if argWord[-len(leaf):] == leaf: return argWord[:-len(leaf)] [/code] Here's for you're first problem. | |
Re: Something along these lines: [CODE] lineCount = 0 while True: theTxt = raw_input("") if theTxt == ".": break lineCount += 1 print theTxt*3 [/CODE] Obviously you can replace the [ICODE]print theTxt*3[/ICODE] with whatever you want, but that's the jist of it. ![]() | |
Re: [code] theySaid = raw_input("Please enter a, b, or c: ") if theySaid not in ["a", "b", "c"]: print "You didn't follow my instructions. Sad Panda..." [/code] | |
Re: Could you rephrase that? I'm not sure if this is what you're after, but: [code] while True: surv1.set_sex = raw_input("What's your gender?") if surv1.set_sex in ["m","f","n"] break else print "Please answer m (male), f (female), or n (neither)." [/code] | |
Re: A quick google search of "python special class methods" pulled up this: [url]http://diveintopython3.org/special-method-names.html[/url] | |
Re: If by manually you mean with 2 for loops or a list comprehension. [CODE] listX = [[0 for i in range(1448)] for j in range(50)] [/CODE] | |
Re: You can use helper functions, you know. [CODE] def harmonicSum(n): def realSum(p): if p > n: return 0 return 1/p + realSum(p+1) return realSum(1) [/CODE] There's probably a more eloquent solution, but what works, works. It also allows you to modify the function slightly to get numbers of the form … | |
Re: First of all, in the code you posted, you never run your main function. | |
Re: [CODE] def population_growth(argBase, argMax, argRate): assert argBase < argMax assert argRate > 0 theAnswer = [argBase] iterAnswer = argBase while True: iterAnswer *= 1+argRate theAnswer.append(iterAnswer) if iterAnswer > argMax: break return theAnswer uBasePop = int(raw_input("Enter the base population: ")) print population_growth(uBasePop, 1000000, .08) [/CODE] I didn't know what you're needs … ![]() | |
Re: If you open a file with the [ICODE]open()[/ICODE] function to write in, and it doesn't exist, then it will be created automatically. Is this what you're looking for? For example, to use your code: [CODE] theFile = open("C:\test.txt","w") [/CODE] EDIT: Wow, my bad, the post below me ninja'd it. I … | |
Re: Python has a built in debugger named pdb (Python DeBugger, lol) that will let you do just that. Check out [URL="http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/"]this article[/URL] for its use and some other debugging | |
Re: Whenever you have an error when dealing with someone else's code that they posted publicly that is relatively popular, it's good to assume that you're code has the error rather than their code. Does [ICODE]MyPhotoSets[0][/ICODE] contain a Photoset object? Maybe you should check. | |
Re: The function range(x,y) returns the list x,x+1,x+2,...,y-1 and stops there. If you wanted to print out x through y in your above function, you should change it to [ICODE]range(first, last+1)[/ICODE] | |
Re: Lol, try making 1000 into 100000. It's doing it too quick and rounding down the time. | |
Re: Yes, you make a Monster class, and a Weapons class, and in the constructor of the Room make a list of the monsters and a list of the weapons. | |
Re: How about: [CODE] area = ((length**2)*numosides/4) / math.tan( math.pi/numosides ) [/CODE] Area isn't in degrees... | |
Re: Look at the beginning of prompt_cell. You misspelled one of the global variables. :) However, your code looks extremely ill-formed. Though it will work like this, this is a very shakey way to write it. Do you know what classes are? Also, you can pass functions as arguments, so you … | |
Re: Here's a technique commonly used to sanitize input: [CODE] keep_going = True while keep_going: choice=int(raw_input("please enter your choice(1 = rock, 2 = scissors, 3 = paper): ")) if choice == 1: choice = 'rock' keep_going = False elif choice == 2: choice = 'scissors' keep_going = False elif choice == … | |
Re: Do you have something against functions that take arguments? You have a lot of functions that could be many into one or two functions with an argument or two. Even if you don't use OOP, getting rid of global variables and putting some functions with arguments into place can't hurt … | |
Re: Use the print function I gave you in the previous thread. For filling the board with blank (-) spaces, you need a seperate function (i.e. the one you have above called print board) to initialize the board. [CODE]GameBoard = [] #this will be the main game board def initialize_board(argR, argC): … | |
Re: You know, it might be helpful to post up your code so we can find errors in it. | |
Re: [QUOTE=mahela007;1045329]So how does a toolkit eliminate the need to write that fundamental code? With the massive number of different graphics cards available today, how could a toolkit possibly know how to access the memory of the video cards? [/QUOTE] How does Windows, or Linux, or <Insert OS Here> know how … | |
Re: The best solution I know of is to print out each thing manually. Example: [CODE] for row in fielda: for spot in row: print spot, print [/CODE] | |
Re: The first two only require one liners of logic, so here: [CODE]n = int(raw_input("How many squares? ")) squares = [x*x for x in range(1,n+1)] print square[/CODE] [CODE]def even_only(argList): return filter(lambda m: m%2==0, argList)[/CODE] As for the pig latin, you'll need to break the sentence down into words with split, do … | |
Re: Normally I'd suggest to use something like mathplotlib, but since he gave you graphics.py, he probably wants you to use it to draw the histograms. Could you attach it to your post? | |
Re: Assuming you already know how to read in from files, there's a wonderful plotting tool for python called [URL="http://matplotlib.sourceforge.net/"]matplotlib[/URL] that will let you make your pie chart. You'll have to get numpy first, though. Btw, your link to the text file is broken. | |
My issue is essentially spelled out in the title. I want to be able to catch clicks (more specifically double clicks) on icons on the desktop or in folders or wherever, and tell where the click was on the icon (the coordinates of the click along with the whole size … | |
Re: This sounds suspiciously like homework, so I'll just give you a hint. someList.index(item) returns the index of the item if it's in some list. Otherwise, it'll throw ValueError. Example: [CODE]listA = [1,2,3,5] try: listA.index(4) print "Four is in the list." except ValueError: print "Four isn't in the list."[/CODE] | |
Re: I've never used turtle before, but that looks similar to Pickle and cPickle. The difference between those two is that since python is kinda slow, they redid the Pickle library with C (cPython) to make it alot faster. | |
This question, as the title says, is specific to the new file tagging feature in Windows Vista. Basically, I want to make a tag cloud for a certain folder, and in order to do this, I need to access all of the tags of the files in the folder. What … | |
Re: I apologize for the childish explanation, but simple concepts should be explained simply. An empty string is a string with no characters in it. Imagine we have a basket of 3 apples. If I take away 2 apples we have 1 apple in the basket. If I take away 1 … | |
Re: How about having a dictionary containing volume, brightness, and contrast? [CODE] def adjust(self, PROPERTY): print self.stats[PROPERTY] adjust = raw_input("") while adjust == "+" or adjust == "-": if adjust == "+": self.stats[PROPERTY] += 1 else: self.stats[PROPERTY] -= 1 if self.stats[PROPERTY] < 0: self.stats[PROPERTY] = 0 elif self.stats[PROPERTY] > 20: self.stats[PROPERTY] … | |
Re: I know this is a Python forum and all, but look at the ad under your post. They have a free trial version, so maybe that'll work out for you. | |
Re: os.listdir(arg) will return a list of all of the names of the files in whatever directory you put in for arg, so that's your first step. Take a look at [url]http://www.python-excel.org/[/url] for the specifics on working with excel spreadsheets. They aren't included with the standard distribution or Python, so you'll … | |
I just started learning Python last week, and I was having a few issues with doing a GUI app in Tk. My main problem is this: I have a list (each member of the list is a frame with a picture and some text in it) that populates itself by … |
The End.