# 2. Calculate the final value of P(X=97)

lambda = 100
k = 97
prob = dpois(k, lambda)
print(prob)
## [1] 0.03867314
# 3. Calculate P(X > 5.8 | X < 7.0) 

z1 = 0.4286
z2 = 2.1429
  
# Find cumulative probabilities
P_x2 = pnorm(z2)    
P_x1 = pnorm(z1)

# Find P(5.8 < X < 7.0)
Prob = P_x2 - P_x1

cond_prob = Prob / P_x2
print(cond_prob)
## [1] 0.323238
# 4.To find x such that P(X>x)=0.57

mean = 0          
sigma = 1.1     
p = 0.43     

# Find the value where 57% of the errors are above it
x = qnorm(p, mean = mean, sd = sigma)
print(x)
## [1] -0.1940116
# 5.Use a simulation to find the probability that it takes longer than 5 minutes 

lambda = 1/3           
n_simulation = 100000         
time_threshold = 5

# Simulate n_simulation waiting times from an exponential distribution with lambda = 1/3

sim_times = rexp(n_simulation, rate = lambda)

# Calculate the proportion of times that exceed 5 minutes
prob = mean(sim_times > time_threshold)

# Print the result
print(prob)
## [1] 0.18718