Another python question
Alan Gabriel
alanunny at gmail.com
Fri Mar 18 18:46:28 EDT 2016
Sorry for the multiple questions but my while loop is not working as intended.
Here is the code :
n = 1
list1 = []
count = 0 #amount of times program repeats
steps = 0 # amount of steps to reach 1
step_list = []
while n!=0:
n= int(input())
list1.append(n)
length = len(list1)
while count < length:
num= list1[count]
while num!= 1:
if num%2 == 0:
num= int(num/2)
print(num)
steps+=1
if num%2 == 1:
num=int(3*num+1)
print(num)
steps+=1
count+=1
step_list.append(steps)
steps=0
This code is meant to get numbers from the user in different lines and convert into a list. When this is done the first while loop runs until it checks all the numbers in the list. The 2nd while loop is meant to stop when the number is equal to 1 however the 2nd while loop keeps running.
Sorry for the bad naming but I was in a rush, ty anyway
More information about the Python-list
mailing list