For some reason this code doesn’t print anything and doesn’t stop running, can anybody tell me what is going wrong here?
l = [1,2]
i = 0
k = l[i]+l[i+1]
while k <= 10:
l.append(k)
i += 1
print l
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The value of
k(and therefore the loop condition) is set before the loop using the current value ofi(0), and never changes during the loop execution. You would have to reassignkbased on the new value foriinside the loop for it to change.