# File: chaos2.py # A simple program illustrating chaotic behavior # # This one does error checking on the input # # Matt Bishop, ECS 10, Winter 2012 # # announce what the program does print("This program illustrates a chaotic function") # ask for a number, but be suspicious try: # ask, and convert it to a float x = float(input("Enter a number between 0 and 1: ")) except ValueError: # oops . . . didn't work; say so print("You need to enter a real (decimal) number between 0 and 1") else: # got it! print("x =", x) # # check to be sure it meets he requirements # if 0 < x and x < 1: # it does # # now apply the chaotic function 100 times # for i in range(100): x = 3.9 * x * (1 - x) print(x) else: # it doesn't -- complan and leave print("Your input is not between 0 and 1")