DEV Community

Cover image for Chaotic Comparison
Scott Gordon
Scott Gordon

Posted on

Chaotic Comparison

# chaotic_comparison.py
#   A simple program comparing chaotic behavior between an x value and
#   a y value in a table format.
# by: Scott Gordon

def main():

    # Add user input for two initial values and the number of iterations.
    print("***** Welcome to Chaotic Comparison *****\n")
    x = float(input("Enter a value between 0 and 1: "))
    y = float(input("Enter a second value between 0 and 1: "))
    print()

    # Print a formatted table showing how the values change over time.
    print(f"index {x:>5} {y:>10}")
    print("------------------------")
    for i in range(1, 10+1):
        x = 3.9 * x * (1 - x)
        y = 3.9 * y * (1 - y)
        print(f"{i:2} {x:>10.6f} {y:>10.6f}")


main()

Enter fullscreen mode Exit fullscreen mode

Photo by Hans-Peter Gauster on Unsplash

Top comments (0)