Question
want to just add this section of the task to my code, and pls very basic level of Python and the only permitted library
want to just add this section of the task to my code,
and pls very basic level of Python and the only permitted library is Pylab.
pls see the attached photo.
from pylab import *
###################### Functions are defined here ###########################
# Constants
tts_predator = 10 # Time to give up for the predator (in seconds)
time_step = 0.1 # Time step for position calculation (in seconds)
# Power law equation for maximal running speed
def maximal_running_speed(mass):
return 10 ** (1.47832 + 0.25892 * log10(mass) - 0.06237 * (log10(mass)) ** 2)
# Power law equation for time to reach top speed
def time_to_reach_top_speed(mass):
return 10 ** (0.16 + 0.25 * log10(mass))
# function that asks the user to press "0" button to move through the program
def button(x):
x=float(input("Press 0 to continue: "))
return x
###################### main body of the code here ###########################
print("Hi there! Welcome to St Lucia Public Science Museum! This exhibition is called'Mother Nature, racing to survive'. Today we will explore the amazing life of animals in terms of chase and prey in order to survive.")
print("Have you ever wondered about the potential of animals, animals speed or chase and compareing the speed of fastes human on earth with them ?")
print("If you have, then prepare to be amazed. If you haven't, then prepare to be mindblown!")
# prompts user to enter their patron type
patron_type = float(input("Press 2 if you are a science rookie OR Press 1 if you are a scienceenthusiast: "))
# begin program for "science enthusiast"
if patron_type== 1:
# display intro about animals speed
print("The vast plains of the Serengeti comprise 1.5 million ha of savanna. The annual migrationto permanent water holes of vast herds of herbivores (wildebeest, gazelles and zebras),followed by their predators, is one of the most impressive natural events in the world.")
print("Can you guess how both predator and prey accelerate to chase/aviod their adversay?")
x=float(input("Press 0 to continue: "))
#explains maximal_running_speed
print("By using the function of maximum running speed equation we can calculate the speed of animals")
print()
button(x)
# start of loop so user can do multiple animals searches if they wish
# prompt the user to enter the values for mass_predator and mass_prey
mass_predator = float(input("Take a guess and enter choose a mass for the predator: "))
mass_prey = float(input("Take a guess and enter choose a mass for the prey: "))
# Mass of the predator (in kg)
max_speed_predator = maximal_running_speed(mass_predator)
print("This predators max speed is", max_speed_predator)
time_to_top_speed_predator = time_to_reach_top_speed(mass_predator)
print("The time to reach it's maximum speed is ", time_to_top_speed_predator)
max_speed_prey = maximal_running_speed(mass_prey)
print("This prey max speed is", max_speed_prey)
time_to_top_speed_prey = time_to_reach_top_speed(mass_prey)
maximal_running_speed
print("The time to reach it's maximum speed is ", time_to_top_speed_prey)
print()
print("If you want to see a plot ")
x=float(input("Press 0 to continue: "))
# use user inputs to set up variables used in functions that calculate orbital period,transit time and minimum relative intensity
log_mass = array([1.48, 1.78, 2.08, 2.38, 2.68])
log_time_to_top_speed = array([0.16, 0.41, 0.67, 0.93, 1.18])
# Calculate the values of a and b in the power law equation for time to reach top speed
a, b = polyfit(log_mass, log_time_to_top_speed, 1)
# Calculate the maximal running speed and time to reach top speed for the predator and prey
mass_predator = 45 # Mass of the predator (in kg)
mass_prey = 250 # Mass of the prey (in kg)
max_speed_predator = maximal_running_speed(mass_predator)
max_speed_prey = maximal_running_speed(mass_prey)
time_to_top_speed_predator = time_to_reach_top_speed(mass_predator)
time_to_top_speed_prey = time_to_reach_top_speed(mass_prey)
# Calculate the number of time steps for the chase
num_steps = int(tts_predator / time_step)
# Arrays to store positions and times
positions_predator = zeros(num_steps)
positions_prey = zeros(num_steps)
times = zeros(num_steps)
# Calculate positions and times for each time step
for i in range(num_steps):
# Calculate current time
times[i] = i * time_step
# Calculate current speed for the predator and prey
if times[i] < time_to_top_speed_predator:
speed_predator = times[i] * max_speed_predator / time_to_top_speed_predator
else:
speed_predator = max_speed_predator
if times[i] < time_to_top_speed_prey:
speed_prey = times[i] * max_speed_prey / time_to_top_speed_prey
else:
speed_prey = max_speed_prey
# Calculate current positions for the predator and prey
if i > 0:
positions_predator[i] = positions_predator[i-1] + speed_predator * time_step
positions_prey[i] = positions_prey[i-1] + speed_prey * time_step
else:
positions_predator[i] = speed_predator * time_step
positions_prey[i] = speed_prey * time_step
# Print the positions and times
for i in range(num_steps-1):
("Time:", times[i], "s - Predator Position:", positions_predator[i], "m - Prey Position:", positions_prey[i], "m")
# Plot the positions of the predator and prey
plot(times, positions_predator, 'o-', label='Predator')
plot(times, positions_prey, 'o-', label='Prey')
# Set the axis labels and title
xlabel('Time (s)')
ylabel('Position (m)')
title('Predator-Prey comprison')
print("As you can see the above graph show the position of a preditor and a prey in time period of 10 second which basically the the time that a mammal reaches it's maximum speed which can determine it's position in chase situation")
# Add a legend
legend()
# Show the plot
show()
print("if you want to compare it the fastes human press 0")
button(x)
# Constants for Usain Bolt's split times
usain_bolt_split_times = [0, 1.88, 2.88, 3.78, 4.64, 5.47, 6.29, 7.10, 7.92, 8.87, 9.58]
# Arrays to store Usain Bolt's positions and times
positions_usain_bolt = zeros(num_steps)
times_usain_bolt = linspace(0, tts_predator, num_steps)
# Calculate positions for Usain Bolt at each time step
for i in range(num_steps):
# Interpolate the position for the current time step using the split times
t = times_usain_bolt[i]
for j in range(len(usain_bolt_split_times) - 1):
if usain_bolt_split_times[j] <= t <= usain_bolt_split_times[j + 1]:
# Linear interpolation
positions_usain_bolt[i] = (t - usain_bolt_split_times[j]) * (10 / (usain_bolt_split_times[j + 1] - usain_bolt_split_times[j]))
break
# Plot the positions of the predator, prey, and Usain Bolt
plot(times, positions_predator, 'o-', label='Predator')
plot(times, positions_prey, 'o-', label='Prey')
plot(times_usain_bolt, positions_usain_bolt, 'o', label='Usain Bolt')
xlabel('Time (s)')
ylabel('Position (m)')
title('Predator-Prey comprison')
#Add a legend
legend()
# Show the plot
show()
if patron_type== 2:
print("so your a science rookie")
5.6 Advanced section modelling a pursuit On the Serengeti, the relationship between a predator and its prey is well established. Each has well-developed skills optimised for survival. The museum staff would like you to model one such pursuit and identify whether the predator catches its prey, based on an initial separation. As this is the advanced section, some aspects are left entirely open, and you will need to think about how best to do both the implementation and the communication to meet the grading criteria found later in this document. More details are also provided in the following section. Remember that the quality of your approach, not the quantity, is important!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The skin friction coefficient Cf for a laminar boundary ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started