- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 17
- Posts with Upvotes
- 13
- Upvoting Members
- 12
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
56 Posted Topics
Re: He is using the graphics file from a python book. Your code for the stick figure would look like this. The Line command uses two points(x,y) for the starting point and (x,y) for the ending point. [CODE]def drawStickFigure(): from graphics import * win = GraphWin("Stick figure") head = Circle(Point(100, 60), … | |
Re: I just look at the code in the Checkbook2 class, and it needs to be reviewed. To get started I updated the fileWriter to print out the correct lines to the file. [CODE] public void fileWriter(){ //Checkbook2 write = new Checkbook2(); //System.out.println("Unavailable"); try{ BufferedWriter out = new BufferedWriter(new FileWriter("Checkbook.txt")); out.write(getName()+"\n"); … | |
Re: [CODE]// Set the host smtp address Properties props = new Properties(); props.put("smtp.host", "smtp.server.com"); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); // create a message Message msg = new MimeMessage(session); //adding an attachment DataSource source = new FileDataSource("pathToFile/filename.zip"); msg.setDataHandler(new DataHandler(source)); msg.setFileName("filename.zip");[/CODE] | |
Re: I would take a look at this article, your computer is fairly old so I would not spend more than $150 on a video card as your CPU will handicap it. [URL="http://www.tomshardware.com/reviews/gaming-radeon-hd-geforce-gtx,2676.html"]http://www.tomshardware.com/reviews/gaming-radeon-hd-geforce-gtx,2676.html[/URL] | |
Re: This part of the forum is for Python questions, you can post your question to hardware and software. | |
Re: Why don't you just use the button class that I gave you in another thread, it would make your life a lot easier if you learn classes. Your problem is that once a click occurs outside of one of the buttons there is no infinite loop to check for the … | |
Re: You can use this button class to create a button with all the methods needed without hard coding every button. [CODE]# button.py # A simple Button widget. from graphics import * class Button: """A button is a labeled rectangle in a window. It is activated or deactivated with the activate() … | |
Re: The button is a sprite which makes it very easy to use many times in the program and easy to customize. [CODE] #load_image is used in most pygame programs for loading images def load_image(name, colorkey=None): fullname = os.path.join('data', name) try: image = pygame.image.load(fullname) except pygame.error, message: print 'Cannot load image:', … | |
Re: Python dictionaries are unordered key-value pairs, so there is no way for them to be in the same order at all times, but recently python version 2.7 was released with a ordered dictionary feature. I have not used any of the 3.0+ versions of python so I don't know if … | |
Re: Hate to say it but there are a lot of problems with your code, but you can only learn from mistakes. First I'm going to address the syntax errors, which should be easy to fix from looking at what the red error text says in your console. Line 27 [CODE]text … | |
Re: I have not used the graphics package cImage, but you can use the built-in random package. To call a random number between 1 and 255 just use the code below. [CODE]from random import randint print randint(1,255)[/CODE] | |
Re: The variable windowSurface is not a global value and is local to the newscreen() method. You can make it that newscreen() returns windowSurface, but it will make your program much more future proof if you wrap these methods in a class, and declare windowSurface as self.windowSurface so that it can … | |
Re: Yes you can run two fans off of the 3 pin connector. You can also connect them into the the power supply cables which run at 12v too, but then they will be running at full speed because of the constant 12v. | |
Re: You can use the time library using import time. You are going to want to use something along the lines of time.sleep([I]Seconds[/I]) [URL="http://docs.python.org/library/time.html"]http://docs.python.org/library/time.html[/URL] I don't really understand what you are talking about with a hour being 5 minutes in a hour and 11 seconds in a minute. | |
Re: [B]Question 1[/B] You do not have to recycle your "choice" variable from your for loop to make the input work. "choice" is being reassigned in this line: [CODE]choice = int(input("Choose an option: "))[/CODE] If you change the later part of your program to this it will still work perfectly. [CODE] … | |
Re: I have not tried it out, but after a quick google search I found this. Looks like it should work. [URL="http://search.cpan.org/~dunniganj/Tk-LineNumberText-0.5/LineNumberText.pm"]http://search.cpan.org/~dunniganj/Tk-LineNumberText-0.5/LineNumberText.pm[/URL] | |
Re: I tested it out and successfully downloaded an Atari game, it is a really cool application. A few things that you may want to change: [LIST] [*]After you download a rom it exits the program, there should be a choice to continue. [*]Is there a reason that you zipped a … | |
Re: I'm little confused on what you are trying to do, but it seems that if a item has a count of 0 then it should not even be active and just have pygame kill() it. If count is enumerating the number of classes on the screen then it is easier … | |
![]() | Re: This should get you started, it will have to be tweaked depending on the infile that you are using. [CODE]def main(): d = {} text1 = ["dog","cat"] infile = open("words.txt","r") #Opening words.txt, r is for read counter = 0 for line in infile: words = line.split(",") #Using "," for delimiter … ![]() |
Re: This will get you started in the right direction, I'm storing the 3 pieces of data for a painting as a tuple. If you want to get the name, you index for list[0], and so on for the other two. [CODE]#returns a list of tuples def createList(): paintingList = [] … | |
Re: vegaseat has a good list of examples in this thread. [URL="http://www.daniweb.com/code/snippet216689.html"]http://www.daniweb.com/code/snippet216689.html[/URL] | |
Re: Give this a try, using [ ] to index in that tuple. [CODE]valuesfor1 = [('WER', 100)] valuesfor2= [('WER', 700)] for tuple1 in valuesfor1: for tuple2 in valuesfor2: if tuple1[0] == tuple2[0]: if tuple1[1] < tuple2[1]: print "values for 2 is greater" elif tuple1[1] > tuple2[1]: print "values for 1 is … | |
Re: This should do it. [CODE]def clear(self): self.elements = {}[/CODE] | |
I'm putting together the basic layout for a contacts book, and I want to know how I can make the 3 test buttons span from edge to edge just as the arrow buttons do. [CODE]import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; … | |
Re: Is there anyway that you can attach the entire program as a zip or pm it. I feel like I can fix the problem, but really need to try it out on the program. | |
Re: This should do it, I did not test it on any files so if there might be an error. [CODE]infile = open("filename.txt","r") wordsDict = {} for line in infile: addBoolean = True for word in wordsDict: if word == line: addBoolean = False break if addBoolean: wordsDict[line] = None infile.close() … | |
Re: I would start with building the board. Then create a class called ship and methods that change the size of the ship and move it. The ships are be stored in a stack for drawing. Mostly likely user input will be from console input, so make sure your board has … | |
Re: What do you have so far? To start you are going index the first and last in the method. [CODE]str = '123456' str[0] #index the first str[-1:]#index the last[/CODE] Then just build a simple recursive method to solve. Post your code if you have any more questions. | |
Re: [CODE]random.uniform(-0.5,0.5)[/CODE] | |
Re: Minor fixes are commented. [CODE]from Tkinter import * import random weapons = ("rock", "paper", "scissors") class Application(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() self.create_widgets() def create_widgets(self): Label(self, text = "Choose your weapon!\n" ).grid(row = 0, column = 0, sticky = W) Label(self, text = "Weapons:" ).grid(row = 1, column = … | |
Re: [CODE]from string import split def main(): testString = "US 9 15 13 37" #using split from the string library #splitting it based on whitespace splitString = testString.split(' ') #now splitString is a list and we remove the first node splitString.pop(0) print splitString #prints as a list #Now just concatenate the … | |
Re: Still a lot that you can add, but this should get you started. [CODE]from string import split class Line: def __init__(self,one,two,three,four): self.one = one self.two = two self.three = three self.four = four class FindMatch: def __init__(self): self.dict = {} def addFromFile(self,filename): infile = open(filename, 'r') for line in infile: … | |
Re: This should solve the problem, below is the correct way to search a dictionary with a for loop. [CODE]def solve(): dict = {9:'B', 8:'C', 7:'D', 6:'E'} choice = raw_input("Please enter a number: ") if int(choice) >= 10: return 'A' elif int(choice) <= 5: return 'F' else: for letter in dict: … | |
Re: Simple example of inheritance in python. [CODE]class Basic: def __init__(self): self.var1 = None #This class inherits all aspects from Basic and can change them class Test(Basic): def __init__(self): Basic.__init__(self) def main(): testClass = Test() testClass.var1 = 5 print testClass.var1 if __name__ == '__main__': main()[/CODE] | |
Re: Simple example taken from pygame.org [CODE]for event in pygame.event.get() : if event.type == pygame.KEYDOWN : if event.key == pygame.K_SPACE : print "Space bar pressed down." elif event.key == pygame.K_ESCAPE : print "Escape key pressed down." elif event.type == pygame.KEYUP : if event.key == pygame.K_SPACE : print "Space bar released." elif … | |
Re: Minor fixes, also if you have problems with libraries just google them or look at Python's documentation. [URL="http://docs.python.org/library/math.html"]http://docs.python.org/library/math.html[/URL] [CODE] from graphics import* import math from random import* def buildWindow(win, position): # Create the y axis lines yAxis = Line(Point(position, -50), Point(position, 50)) yAxis.setFill("black") yAxis.draw(win) # Create the x-axis lines xAxis … | |
Re: [CODE]infile = open('InputFileName.txt', 'r') for line in infile: #line is one string print line[/CODE] | |
Re: Played the game twice and I did not have the problem with formation being broken. | |
Re: Put them into a class. Then you can store them all in a list if you like. Sample class [CODE]class Monster: def __init__(self): #Store the unit attributes self.hp = 25 self.type = 'bird' self.attackDmg = 15 self.defence = .5 def attcker(self,unitBeingAttacked) dmgDone = self.attackDmg*unitBeingAttacked.defense[/CODE] | |
Re: I put your program in a class which is useful if you need to use it later in a different program. The below comments explain a few pointers. If you have any questions just ask, classes can be confusing at first. [CODE]import random #Code should always be in a method … | |
Re: Works fine now, just had to indent the last few lines of code into your main. [CODE]from graphics import * import time def moveAll(shapeList, dx, dy): for shape in shapeList: shape.move(dx, dy) def moveAllOnLine(shapeList, dx, dy, repetitions, delay): for i in range(repetitions): moveAll(shapeList, dx, dy) time.sleep(delay) def makeFace(center, win): head … | |
Re: The os is not even meant for primary computers, it is made for secondary computers and boots from flash memory. All programs and files are saved on the internet, it will be great for tablets and day to day uses, but don't plan on playing games on chrome. | |
Re: Just little errors, first need to use raw_input() when inputting strings, and have to use a different variable instead of search in the for loop. [CODE]def main(): list_of_names = open_file() print""" --------------- non sorted---------------------""" print_names(list_of_names) print """ ----------------sorted-------------------------""" list_of_names = sort_names(list_of_names) save_file(list_of_names) search_names(list_of_names) def open_file(): list_of_names = [] name = … | |
Re: Pretty sure this will work. If you have any questions just ask. [CODE]from string import find def main(): infile = open("logfile.txt", "r") pastLine = infile.readline() cont = 0 for line in infile: if cont == 1: if find(line,'-------') > -1: #find returns -1 if not found cont = 0 print … | |
Re: Most people will not want to download .zip files, it is better if you copy and paste your code between the CODE tags. | |
Re: It is considered a null string, which is ''. [CODE]a = raw_input("Enter your first name:") b = raw_input("Enter your last name:") c = raw_input("Enter your phone number:") print a print b print c d = (a and b and c) print d if d == '': print "Do not leave … | |
Re: This code is taken from the aliens.py example from pygame.org. [URL="http://www.pygame.org/docs/ref/examples.html#pygame.examples.aliens.main"]http://www.pygame.org/docs/ref/examples.html#pygame.examples.aliens.main[/URL]] [CODE]class Score(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.font = pygame.font.Font(None, 20) self.font.set_italic(1) self.color = Color('white') self.lastscore = -1 self.update() self.rect = self.image.get_rect().move(10, 450) def update(self): if SCORE != self.lastscore: self.lastscore = SCORE msg = "Score: %d" % SCORE self.image = self.font.render(msg, … | |
Re: It is easy to open up a laptop and remove the hard drive, he might have done that. | |
Re: Can you please be more clear, from what I understand you want 8 eyes total to be printed out on the screen, but with the radius size of 40 you have, all there is room for is a single eye before overlap. | |
Re: [CODE]def population(): current=input("please enter the current population of the city: ") yearCount = 1 print "At year 0 The population is ",current while current < 1000000: current += current*0.08 print "At year ",yearCount,"The population is ",current yearCount += 1 if __name__ == '__main__': population()[/CODE] ![]() |
The End.