Aug-18-2023, 11:14 PM
Im taking a Intro to Programming Course for my Associate's in Computer Information Systems. The book im using is Python Programming, Intro to Computer Science by John Zelle. Im using Python Idle Shell 3.11.4. In the first chapter it gives an example of a chaos function, and then asks questions on how to make changes or improvements to it to provide different results.
The one im stuck on asks to take two inputs and display two columns side by side. Ive got it to do that, but in the first column it starts producing the same number, where as the second column contains chaos numbers. In a single instance of the math part it works fine but when I add the second math part, it makes the first column just display the same number over and over again.
Im not sure what's not quite right as i've changed variable names and added redundancy for them to try and make sure the number to be processed isn't getting stuck or looped somewhere, which it seems like it's doing. Can anyone give me a hint as to what line or change needs to be made so both columns work independently of each other but still be in the same over all function? Code below:
The one im stuck on asks to take two inputs and display two columns side by side. Ive got it to do that, but in the first column it starts producing the same number, where as the second column contains chaos numbers. In a single instance of the math part it works fine but when I add the second math part, it makes the first column just display the same number over and over again.
Im not sure what's not quite right as i've changed variable names and added redundancy for them to try and make sure the number to be processed isn't getting stuck or looped somewhere, which it seems like it's doing. Can anyone give me a hint as to what line or change needs to be made so both columns work independently of each other but still be in the same over all function? Code below:
def main(): print("This program illustrates a chaotic function") 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) for i in range(o): y=3.9*y*(1-y) print(x,y)And I get results like this:
Output:main()
This program illustrates a chaotic function
how many numbers should I print?6
how many numbers should I print?6
Enter a number between 0 and 1: .2
Enter a number between 0 and 1: .3
0.694155708424637 0.819
0.694155708424637 0.5781321000000001
0.694155708424637 0.951191962303401
0.694155708424637 0.18106067129594494
0.694155708424637 0.5782830479626462
0.694155708424637 0.9510998811665442