Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bob.may.py: USE PYTHON print(\"The one point iteration that brought chaos into f

ID: 3673018 • Letter: B

Question

Bob.may.py: USE PYTHON
print("The one point iteration that brought chaos into focus!")
print('Try these values of r: 3, 3.5, 3.544099, 3.56445, 3.568759')

r=float(input('Enter the value of r = '))
N=10000
x=[0 for i in range(0, N)]
x[0]=0.7
index=[0 for i in range(0, N)]

#=============================================
# Main iteration
#=============================================

for n in range(1,N):
index[n]=n
x[n]=r*x[n-1]*(1-x[n-1])

# Let us print the last 100 values
print('The last 4 values are:')
print(x[N-4], ' , ',x[N-3],' , ', x[N-2], ' , ', x[N-1])

#=============================================

# Plotting
import matplotlib.pyplot as plt
plt.plot(index[N-100:N], x[N-100:N])
plt.show()
#=============================================

Exception handling with continue statement: Sometimes when a user is asked for a data he may make an error. For example, if numeric data is asked he may enter a string. We do not necessarily want the program to exit. We may want to give a warning to the user. In such cases, we can use a Python keyword continue. Here is a toy example: while True num-str = input ("Enter a number: ") try if num str!-"done" num=float (num-str) # The code does nothing else: break except: print ("If you are finished enter : done, else enter a number") continue

Explanation / Answer

while True:
   print("The one point iteration that brought chaos into focus!")
   print('Try these values of r: 3, 3.5, 3.544099, 3.56445, 3.568759')
   r=input('Enter the value of r = ')
   try:
       if r!="done":
           r=float(r)
           N=10000
           x=[0 for i in range(0, N)]
           x[0]=0.7
           index=[0 for i in range(0, N)]
#=============================================
# Main iteration
#=============================================
           for n in range(1,N):
                index[n]=n
                x[n]=r*x[n-1]*(1-x[n-1])
# Let us print the last 100 values
               print('The last 4 values are:')
               print(x[N-4], ' , ',x[N-3],' , ', x[N-2], ' , ', x[N-1])
#=============================================
# Plotting
   import matplotlib.pyplot as plt
   plt.plot(index[N-100:N], x[N-100:N])
   plt.show()
   continue
#=============================================
       else
           break
   except:
       print("If you are finished enter : done, else enter number.")
       continue