Как мне написать эту программу
Yeah, so, so far i have got a basic program running. I need some help with this and would appreciate it. So i need the finall numbers of each animal to add up to 10 ( the same as the iterations). How would I do this? Here is my code. from random import * PUMA = 0 SNAKE = 1 HAWK = 2 survivalofthefittest = [[0, -1, 1], [1, 0, -1], [-1, 1, 0]] n = int(input("Number of iterations:")) animal1=0 animal2=0 nDraws=0 population = 10* [PUMA] +10*[SNAKE] +10*[HAWK] # Needs to be while loop for _ in range(n): animal1=choice(population) animal2= choice(population) value = survivalofthefittest[animal1][animal2] if value>0: animal1 += 1 elif value <0: animal2 +=1 else: nDraws +=1 print (f"Number of hawks = {HAWK}, Number of pumas = {PUMA}, Number of snakes = {SNAKE}") # Final Numbers of Animals should equal 10
Что я уже пробовал:
from random import * PUMA = 0 SNAKE = 1 HAWK = 2 survivalofthefittest = [[0, -1, 1], [1, 0, -1], [-1, 1, 0]] n = int(input("Number of iterations:")) animal1=0 animal2=0 nDraws=0 population = 10* [PUMA] +10*[SNAKE] +10*[HAWK] # Needs to be while loop for _ in range(n): animal1=choice(population) animal2= choice(population) value = survivalofthefittest[animal1][animal2] if value>0: animal1 += 1 elif value <0: animal2 +=1 else: nDraws +=1 print (f"Number of hawks = {HAWK}, Number of pumas = {PUMA}, Number of snakes = {SNAKE}") # Final Numbers of Animals should equal 10