2

When I run the program below, it outputs all the numbers as 0.0. How can fix this to illustrate chaotic behaviour?

# A simple program illustrating chaotic behaviour

def main():
    print ("This program illustrates a chaotic function")
    x = int (float(input("Enter a number between 0 and 1: ")))
    for i in range(10):
        x = 3.9 * x * (1-x)
        print (x)

main()
Tanaka
  • 301
  • 2
  • 13

2 Answers2

2

In the line where you get input, you take the number and make it an integer. Making something an integer removes all decimals. When you type in ‘0.54’, then the int function takes off the decimals leaving just 0.

If you just do x = float(input("Enter a number between 0 and 1: ")) then it will work.

Have a nice day!

ddg
  • 1,090
  • 1
  • 6
  • 17
0

Actually u have a +1 or - 1 in end will help