![]() So all of this so far has just been enough to get you to your original problem: you are getting an iteration (each consecutive value on a seperate line). Then get rid of that extra space, white space means something in python, though here it doesn't really make a difference: a,b = 0,1 So for your code that would translate to: a,b = 0,1 ![]() Then, if you are expressing more than one variable you can just list all the variables separated by commas equal to all the values separated by commas like this: a,b,c,d = 1,2,3,4 So print(b) needs to be changed to print(a): a = 0 It will read (on separate lines of course) 1,2,3,5,8,13 and so on. If you have it printing b then the fibonacci sequence you get is missing its first 1. Then, the last phrase in this code says print(b). The value of the while loop will be set to TRUE so that the loop will not exit in the future. For this method, we are using a while loop instead of a normal for loop. so get rid of the brackets around them: a = 0 Fibonacci Generator Using Python For Infinite Values The Fibonacci generator will be able to print the value for infinite times. Then, the variables that were myArray1 and 2, but are now a and b those are integers and they do not need to be expressed as single object lists. Here at first, you have declared a to hold an integer type and later you have assigned a function to it and so its type now became a function. First because it is just too long second because in python it is called lists, not arrays third because you are referring to integers, not lists or arrays: a = the type of a variable is determined at runtime and it can vary as the execution is in progress. I would change the phrase myArray1 and 2 to a and b respectively. MyArray1, myArray2 = myArray2, myArray1+myArray2 This code will iterate correctly if you switch out b with myArray2: myArray1 = You don't declare it and it does not belong. The other part of the reason you are getting errors is because of the variable b. MyArray1, myArray2 = b, myArray1+myArray2 I believe that you may be thinking it has something to do with iteration or tuples, but that is part of the reason you are getting errors: myArray1 = Using some completely elementary mathematics (and without having to use any fancy theorems you haven't yet studied) you can prove the following.There are two kinds of mistakes you are making mistakes that are creating errors and mistakes that are affecting readabilityīoth instances of the phrase should be removed. ![]() Option 2 could work as a good strategy, especially when more and more primes are discovered, provided we know how to test if a number is in the Fibonacci sequence. The few Fibonacci numbers we saw above looked quite sparse so Option 1 might look good, but it would require us to test whether a number is prime or not, which as we saw involves quite a bit of effort as the numbers get larger. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |