No matter what I try I keep getting an infinite loop with this function:
# Excercise 33 - LPTHW
i = 0
numbers = []
#Ec 1
#numb = 6
#iplus = 10
def theloop(numb):
global i
#i = 0
#number = []
while i < numb:
print "At the top of i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
print "The numbers: "
for num in numbers:
print num
theloop(7)
When I run the script it just keeps printing:
At the top of i is 0
At the top of i is 0
...
Thanks in advance.
Your code works for me as written, but looks to have weird indentation due to use of mixed tabs and spaces. When I read your script using .readlines, you can see this:
So I’d recommend switching to four spaces everywhere and having another go. Note the difference in the number of tabs between the print statement and the append/increment statements.