Reputation: 65
I want to generate a sequence of numbers starting from 2 and calculating each successive number in the sequence as the square of the previous number minus one.
x = 2
while 0 <= x <= 10:
x ** 2 - 1
print(x)
note: Iam interested in finding the first number in the sequence greater than ten or less than zero
but the loop keeps repeating with the same answer of 3. how do i stop it?
Upvotes: 1
Views: 113
Reputation: 422
You have to update the value of x so that the while
statement will eventually be false.
x = 2
while 0 <= x <= 10:
x = x ** 2 - 1
print(x)
Upvotes: 2
Reputation: 140148
you're not affecting x
x = 2
while 0 <= x <= 10:
x = x ** 2 - 1
print(x)
Upvotes: 4