Python, where of course the expected number of zombies killed is a maximum and sometimes the function says less were killed.
importrandom# n: number of zombies
# r: range in meters
# a: number of bullets
defzombie_shootout(n,r,a):zombie_speed=0.5# m/s
bullets_per_second=1# bullet/s
miss_rate=.05# %
zombie_distance=rnumber_zombies=nnumber_bullets=awhileTrue:#print(zombie_distance, number_zombies, number_bullets)
# if shoot all zombies:
ifnumber_zombies<=0:return"You shot all %s zombies."%n# if get eaten:
ifzombie_distance<=0.0:return"You shot %s zombies before being eaten: overwhelmed."%(n-number_zombies)# if run out of ammo:
ifnumber_bullets<=0:return"You shot %s zombies before being eaten: ran out of ammo."%(n-number_zombies)zombie_distance-=zombie_speednumber_bullets-=bullets_per_secondzombie_killed=1ifrandom.randint(1,100)>95:zombie_killed=0number_zombies-=zombie_killedprint(zombie_shootout(3,10,10),"\nYou shot all 3 zombies.\n")print(zombie_shootout(3,3,3),"\nYou shot all 3 zombies.\n")print(zombie_shootout(3,4,4),"\nYou shot all 3 zombies.\n")print(zombie_shootout(10,2,30),"\nYou shot 4 zombies before being eaten: overwhelmed.\n")print(zombie_shootout(10,30,4),"\nYou shot 4 zombies before being eaten: ran out of ammo.\n")
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python, where of course the expected number of zombies killed is a maximum and sometimes the function says less were killed.