• Content count

  • Joined

  • Last visited

Community Reputation

101 Neutral

About monkey_32606

  • Rank
    Advanced Member
  1. Linux C++ IDE, What do you use?

    VIM or gedit depending on how I'm feeling that day. Gedit is actually quite nice for a code editor.
  2. Bullets directional path

    You're going to have to give them a direction vector eventually. Given that polar coordinates (angle and distance) are converted to cartesian coordinates (x and y) using sine and cosine, I expect most people are going to say yes. Those same transforms also work for 3 dimensions.
  3. You're having to catch an exception because you're popping elements off of your phrases list and when it reaches the end there is no phrase to remove from the empty list. You've got a couple of options on how to handle this. First option; keep track of the number of elements in the list and simply not pop the last one. Second option; iterate over every element in the list of phrases using a for loop. The second piece of code I posted uses this method. While it's not really wrong, most people would recommend that you not deliberately trigger exceptions to break out of code either.
  4. Multiplayer Building games

    Holy crap, Active worlds is still around? I was first introduced to that sometime back in like 98 or 99. Oh, and Minecraft is really neat.
  5. A suggestion: # use a bool instead of those quitnow = "quitnow" a = True # note capital T (lower case true is undefined) b = False # as above if a: print "You will see this." if b: print "You will NOT see this." I had another but I forgot it while I was typing this one up. :(
  6. Hopefully I don't give away too much here: Using the for loop in python you can iterate over every element in a list without slicing or any stupid tricks. Nest a while loop and you're done. If you need the responses simply declare a list somewhere outside your loops and append the user inputs to it. ques = ["Are you a plant?", "Are you a man?"] resp = [] for q in ques: while 1: userinp = str(raw_input(q+" ")) resp.append(userinp) if userinp == "yes": break else: continue # don't actually need this, it restarts the inner while E: Judging by your post this doesn't actually do what you want. Something more similar to what you were trying to do is this: # Added some comments import random no = random.randint(1,10) ques = ["Want to play? [yes/no]", "Again, want to play? [yes/no]"] userinp = "" for q in ques: # for every element in ques assign it to q and do the following userinp = str(raw_input(q+" ")) # get our userinput if userinp == "yes": # they answered yes to one of our questions while 1: # prompt the user for a guess, forever guess = int(raw_input("Guess a number 1<n<10: ")) if guess == no: # they guessed right print "Got it!" break # break out of while loop else: # guess again print "Try again." break # leave for loop (quits) else: # they didn't answer yes continue # go on to the next question Sorry, took me a couple of minutes to test that. [Edited by - monkey_32606 on August 19, 2009 11:23:43 AM]
  7. 20/20 If I Only Had a Gun

    Here's my view: Basically we live in a free society. Our society values the human right to self defense. That's what life, liberty, and the pursuit of happiness (property) mean. A gun equalizes the playing field and gives everyone equal access to their right to life. Whereas in olden days a big strong guy could just take whatever property, life, or woman he pleased. Now anybody can defend their property or life with no big strong guy of your own required. Attempting to take away my self defense tool is the first step in trying to take away my life. It saddens me that so many in this world live their lives without grasping this idea or worse understand too late. There are always going to be those who take advantage of this, and maybe they get the drop on a few people, but I'd rather put my skills and training work than cower in the corner waiting for some asshole to shoot me.
  8. Implementing Massive levels

    Quote:Original post by loufoque Quote:A double precision number can represent around 70,000,000,000 (70 thousand million) kilometers to millimeter precision before it starts to lose accuracy. Except operations on floats are faster than those on doubles. Really much faster on some architectures. I suppose that's possible that floating point operations could be faster than double operations but in the grand scheme of things I doubt it would matter.
  9. what's a good python text editor?

    import os os.system("pause")
  10. Adding a bounce to a parabolic projectile

    Using your method what you're trying to achieve is quite complex. It is for this reason that you'll find a lot of people keep the instantaneous velocity and acceleration to work with instead of using the kinematic equations.
  11. php help

    XAMPP is a very good choice as well, it comes with a full WAMP stack + mail and FTP
  12. python: paring down the number of ifs

    Cool, this is why I come here. People like Zahlman explain neat stuff. I had no idea you could do that with getattr. I like making help and quit a special case (which fixes some problems). The reason it has that stupid quitflag is because break would only leave the first for loop (DURRRR) E: It was pretty trivial to add user defined variables too. I made them as a dictionary. The form is something like this: >>> a 42 set Uservars: {'a': 42} >>> a 1 + Defined variables are expanded. Stack: [43] In that example 'a' and 42 are pushed onto the stack. 'Set' pops them and adds a key value pair to the uservars dictionary. The parser looks for keys matching the token in the uservars dictionary and pushes the value of that onto the stack. The only weird thing that can happen is that you can define a key in a python dictionary to be almost anything. E.G.: >>> pi 42 set Uservars: {'3.14159.....':42} This particular pair is inaccessible (and crashes the current implementation) [Edited by - monkey_32606 on April 18, 2008 3:06:27 PM]
  13. python: paring down the number of ifs

    Thanks for the help. This seems like one of the situations where it may actually be more readable to use the elifs :( Anyways, I've expanded and updated the scope of the calculator since I posted this to include much of the python math library. I think right now it could be used as a general purpose calculator; as long as you ignore the lack of error checking (for instance if you try to add with no values on the stack, python has a kitten). If anyone wants it here's the code for the rpnCalc module which does not yet use a dictionary; a read eval print loop would be easy to implement in Tk or Wx or just about anything. rpnCalc Module import math #(C) 2008 Travis Fickett released under the terms of The MIT License class rpnCalc: stack = [] quitflag = False def evalinput(self, instring = ""): tokenlist = instring.split() for token in tokenlist: if token.isdigit(): self.stack.append(token) elif token == "+": self.stack.append(float(self.stack.pop())+float(self.stack.pop())) elif token == "-": self.stack.append(float(self.stack.pop())-float(self.stack.pop())) elif token == "*": self.stack.append(float(self.stack.pop())*float(self.stack.pop())) elif token == "/": self.stack.append(float(self.stack.pop())/float(self.stack.pop())) elif token == "^": self.stack.append(float(self.stack.pop())**float(self.stack.pop())) elif token == "pi": self.stack.append(math.pi) elif token == "e": self.stack.append(math.e) elif token == "pop": self.stack.pop() elif token == "swap": a = self.stack.pop() b = self.stack.pop() self.stack.append(a) self.stack.append(b) elif token == "drop": # drop all values from the stack self.stack = [] elif token == "ln": self.stack.append(math.log(float(self.stack.pop()))) elif token == "log": self.stack.append(math.log10(float(self.stack.pop()))) elif token == "sin": self.stack.append(math.sin(float(self.stack.pop()))) elif token == "cos": self.stack.append(math.cos(float(self.stack.pop()))) elif token == "tan": self.stack.append(math.tan(float(self.stack.pop()))) elif token == "p": print str(self.stack.pop()) elif token == "i": self.stack.append(str(raw_input("......>"))) elif token == "load": #not yet implimented pass elif token == "halp" or token == "help": print "This is a reverse polish notaion (RPN) calculator." print "Operations are evaluated left to right and results are pushed onto the stack." print "Example >>> 9 1 2 + ----> [9, 3]" print "Cont'd >>> + ----> [12]" print "Cont'd >>> 36 / ----> [3] (division may seem counter intuitive)" print "Operands: +-*/^ " print "Commands: pi e pop(erase top) p(print) swap(top two) drop(entire stack)" print "Trig Functions: sin cos tan (operate in radians)." elif token == "q": print "Bai!" self.quitflag = True else: self.stack.append(token) #Released into the public domain 2008 by Travis Fickett import rpnCalc print "Type \'halp\' for directions. (\'q\' for quit)" rpn = rpnCalc.rpnCalc() while rpn.quitflag == False: #READ EVAL PRINT LOOP instring = str(raw_input(">>> ")) print instring rpn.evalinput(instring) if rpn.quitflag == True: # dirty stupid hack break print "Stack:",rpn.stack
  14. So I wrote this dead simple rpn calculator in python last night. It works just fine but there has to be a better way to map to the various operations instead of all of these elifs. import math stack = [] print "Type \'halp\' for directions. (\'q\' for quit)" quitflag = False while 1: input = str(raw_input(">>> ")).split() print input for token in input: if token.isdigit(): stack.append(token) elif token == "pi": stack.append(math.pi) elif token == "pop": stack.pop() elif token == "p": print str(stack.pop()) elif token == "+": stack.append(float(stack.pop())+float(stack.pop())) elif token == "-": stack.append(float(stack.pop())-float(stack.pop())) elif token == "*": stack.append(float(stack.pop())*float(stack.pop())) elif token == "/": stack.append(float(stack.pop())/float(stack.pop())) elif token == "^": stack.append(float(stack.pop())**float(stack.pop())) elif token == "halp": print "This is a reverse polish notaion (RPN) calculator." print "Operations are evaluated left to right and results are pushed onto the stack." print "Example >>> 9 1 2 + ----> [9, 3]" print "Cont'd >>> + ----> [12]" print "Cont'd >>> 36 / ----> [3] (division may seem counter intuitive)" print "Operands: +-*/^ " print "Commands: pi (push pi); pop (pop stack); p (print)" elif token == "q": print "Bai!" quitflag = True else: stack.append(token) if quitflag == True: # dirty stupid hack break print "Stack is:",stack Anybody got any great ideas? I'd love to hear them.