Mekire's Profile User Rating: -----

Reputation: 111 Stalwart
Active Members
Active Posts:
206 (0.45 per day)
11-January 13
Profile Views:
Last Active:
User is offline Today, 08:51 AM

Previous Fields

Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Icon   Mekire has not set their status

Posts I've Made

  1. In Topic: Why is this only looping once?!

    Posted 17 Apr 2014

    It's your turn now. Look into try/except. Look into string methods. Try something. Post back with your code. Use code tags.

  2. In Topic: Why is this only looping once?!

    Posted 17 Apr 2014

    View Postz03, on 17 April 2014 - 03:24 PM, said:

    and the last two lines are indented in my actual code
    Time to start using code tags.

    Your code:
    while numYears <= 0:
        print 'Number of years must be > 0'
        numYears = raw_input('Enter number of years for population to grow: ')

    raw_input returns a string. You are trying to compare it to a number. In python 2 strings are always greater than numbers:
    >>> print("" > 0)
    >>> print("-5" > 0)

    You need to convert your input to an int.
    years = -1
    while years <= 0:
        print("Number of years must be > 0")
        years = int(raw_input("Enter number of years for population to grow: "))

    Now of course, if you enter something other than an integer, your program will go down in flames. Your next step should probably be solving this problem.

  3. In Topic: Easy program improvements?

    Posted 16 Apr 2014

    Currently you are falling into a pattern very common with beginning Python programmers; you want to count everything. When we know how many iterations we need we generally use for loops over while loops. Also you can take advantage of builtins like sum to greatly simplify things.
    import random
    FLIPS = 100
    print("\tFlips a coin 100 times and prints the result.")
    choice = "yes"
    while choice in ("yes","y"):
        heads = sum(random.choice((True,False)) for _ in range(FLIPS))
        tails = FLIPS-heads
        template = "\nAfter {} coin flips, you got {} heads, and {} tails."
        print(template.format(FLIPS, heads, tails))
        choice = input("Want to flip again?: ").lower()
    input("\n\nPress enter to exit")

  4. In Topic: Adding a collision in in Pygame

    Posted 14 Apr 2014

    View PostDK3250, on 14 April 2014 - 08:13 AM, said:

    Spritecollide checks for collision between a single sprite and a group of sprites.
    To check for collision inside a group, you need (in a loop) to remove one sprite from the group, check for collision between this single sprite and the remaining group and finally add the sprite back to the group.

    Rather than remove the sprite from the group and put it back in, you can write a custom callback function for the spritecollide function.

    It would look like this:
    def collidable(one,two):
        if one is two:
            return False
            return pygame.sprite.collide_rect(one, two)

    Now when you want to do collision detection within the same group (but not have a sprite collide with itself) call sprite collide something like this:
    collision = pygame.sprite.spritecollide(self, group, False, collidable)
    Where self is the instance doing the check and group is the group it belongs to (and is checking collision against).

    Writing collision callbacks is something often overlooked in pygame but it can be quite powerful.

    Full example here just for kicks:
    Intergroup collision: Callback method.
  5. In Topic: Running Python 2.7 Games in 3.3

    Posted 12 Mar 2014

    I have a repo of pygame examples; all of which are mutually compatible with 2 and 3.
    It is true a lot of people write there programs with only 2 in mind but there is nothing stopping them from being written on 3. Usually the differences are so trivial that mutual compatibility is quite easy.


My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown
Amakusa, Japan

Contact Information



Page 1 of 1
  1. Photo

    RetroGamer Icon

    13 Dec 2013 - 10:48
    Thanks man for the help awesome work!
Page 1 of 1