DEV Community

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

Collapse
 
maskedman99 profile image
Rohit Prasad

Python

import random

n = int(input('Enter the number of Zombies: '))
r = float(input('Enter the range: '))
a = int(input('Enter the number of ammo: '))

def zombie_shootout(n,r,a):
        n1 = n
        for i in range(a):
                if n == 0:
                        return "You shot all "+str(n1)+" zombies."
                if r == 0:
                        return "You shot "+str(n1-n)+" zombies before being eaten: overwhelmed."
                if a == 0:
                        return "You shot "+str(n1-n)+" zombies before being eaten: ran out of ammo."

                x = random.randint(1,100)
                if x <= 5:                      # Missed the shot
                        a -= 1
                        r -= 0.5
                else:                           # Zombie Killed
                        a -= 1
                        n -= 1
                        r -= 0.5

        return "You shot "+str(n1-n)+" zombies before being eaten: overwhelmed."

print(zombie_shootout(n,r,a))