Python Forum
Help with chaos function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with chaos function
#11
Hi @dbrown8978 ,
I think you found out by now how to print the chaotic numbers side by side, and learned why you should not use "eval()".
But now for something completely different. The task was to write a "chaos()" function, but you did not do so. You wrote a "main()" function which was not used as a function, instead it did all the work.
I think you should have created a "chaos()" function like this:
print("This program illustrates a chaotic function")

def chaos(base, anumber):
    """ This is a function which mixes together some numbers
        to produce another. """
    return base * anumber * (1 - anumber)


numberofrows = int(input("how many rows should I print? "))
x = float(input("Enter a number between 0 and 1: "))
y = float(input("Enter a number between 0 and 1: "))

for i in range(numberofrows):
    x = chaos(2.9, x)
    y = chaos(3.9, y)
    print(f"{x:<20}  {y:<20}")
Output:
This program illustrates a chaotic function how many rows should I print? 6 Enter a number between 0 and 1: .2 Enter a number between 0 and 1: .3 0.46399999999999997 0.819 0.7212416 0.5781321000000001 0.583051247845376 0.951191962303401 0.7049972216708452 0.18106067129594494 0.6031308034109796 0.5782830479626462 0.694155708424637 0.9510998811665442
Reply
#12
I appreciate the help as I still wasnt able to get it on my own but will look over your guy's suggestions and see what I can make do with. Somehow im supposed to make it happen with just what they give me in chapter one, and im using the code verbatim as they give me so I wouldnt know any other way. Right now it gives me an output of:
Output:
xsamenum ywhatevernum xsamenum ywhatevernum xsamenum ywhatevernum
And im looking for an output of:

Output:
xwhatevernum ywhatevernum xwhatevernum ywhatevernum xwhatevernum ywhatevernum
Using pretty much only what's in here, granted there is some redundancy as I see as I move into the next chapter:

def main():
    print("This program illustrates a chaotic funtion")
    n=eval(input("How many numbers should I print?"))
    o=eval(input("How many numbers should I print?"))

    x=eval(input("Enter a number between 0 and 1:"))
    y=eval(input("Enter a number between 0 and 1:"))
    
    for i in range(n):
        x=2.9*x*(1-x)
        print(x)
   
        
    for i in range(o):
        y=3.9*y*(1-y)
        print(y)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Kalman Filter for predicting randomized chaos in Jupyter Labs hbyte 0 1,541 Jan-02-2021, 05:11 PM
Last Post: hbyte

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020