00:01
So in this exercise, we want to modify the chaos program, which i've already loaded up, so that it takes in two inputs instead of one input and displays two columns of outputs instead of just one stream of outputs.
00:11
So let's review what this chaos program does.
00:13
We're going to run the program by calling python, and then the name of the file that we're working at, which i called exercise .py, and it asks us to illustrate a chaotic function, enter a number between 0 and 1, so i'll do that, 0 .25.
00:29
And we see that it prints out sort of the chaotic behavior, a stream of chaotic behavior here.
00:35
Great.
00:36
So let's clear our output, and let me close that window, and let's begin modifying this program.
00:43
So this line here, line 2, is the line that takes in one input, so we're going to go ahead, put another line, just like it, i just copied and pasted it, to create another input line.
00:55
So i'm going to say enter another number instead of enter a number so that the user isn't confused.
01:01
I'm also going to call this y.
01:03
And the reason why i'm calling this y is because if we call this x, then what would happen is that once the user inputs a number here, that number becomes, x becomes that number, but then when the user enters the next number, then x becomes that second number, erasing the first number from sort of the view of the program.
01:26
And likewise here, we are updating x, so we're going to go ahead and copy and paste that.
01:31
And i'm going to change every x here so that it updates y because we want to treat y as we treated x.
01:37
So instead of this x, i'll do y, y, and y.
01:42
And finally, when we're printing, we want to print both x and y, and what i'm going to do is i'm going to print x comma, and then these quotation marks to create a string.
01:52
I'm going to put one, two, three spaces, and then comma y.
01:57
And the reason why i'm adding this is just so there's a little bit of spacing between x and y.
02:02
And what i'm also going to do is i'm going to go ahead, put a print statement before we start going into the loop, and i'm going to put in input comma x, and then comma one, two, three, comma y.
02:17
And it's just saying what the inputs are at the beginning of our output.
02:22
So let's go ahead and run this program.
02:25
So i'm going to call python exercise .py, exercise .py being the name of the file, and it asks us for a number, and then it asks us for another number, so i'm going to do 0 .26.
02:39
And we see that we have input, and then it tells us our inputs, and then it has two columns of outputs.
02:46
So a little problem here because of this input, it pushes our inputs to the right a little bit.
02:51
So what i'm actually going to do is i'm going to add some spaces here.
02:56
So i'm going to put quotation marks here, and instead of having input, because these numbers are not inputs, i'm going to put the same number of spaces as input.
03:08
So input is i -n -t -u -t, and if we go ahead and run this program again, 0 .25, 0 .26, we see that it lines up a little bit better.
03:20
And in sort of the python level that we are currently at, this is about as much as we expect from students, but let's take it a step further and make these columns really, really nice.
03:32
So the first thing i'm going to do is i'm going to comment at this print statement, and basically this is telling the code not to run this line.
03:42
We're going to replace it with a better system.
03:45
So i'm going to walk you through this...