DEV Community

Discussion on: Daily Challenge #192 - Can you Survive the Zombies?

Collapse
 
allgunblazin profile image
R I P 3 F R A M E S

here's my solution in Python

from random import choices

def zombie_shootout(zombies, distance, ammo):
    population = [0,1]
    distribution = [0.05, 0.95]
    zombies_killed = 0

    for i in range(distance*2):
        if ammo == 0 and zombies_killed < zombies:
            print("You killed %d zombies before being eaten: out of ammo" % zombies_killed)
            return

        if zombies_killed == zombies:
            print("You killed %d zombies and survived" % zombies_killed)
            return
        hit = choices(population, distribution)
        if not hit:
            ammo -= 1
            print(hit)
        else:
            ammo -= 1
            zombies_killed += 1

    if zombies_killed < zombies:
        print("You killed %d zombies before being eaten: overwhelmed" % zombies_killed)