Learning from "Automate The Boring Stuff" by Al Sweigart. At the end of Chapter 3, the Collatz Sequence is given as practice. The output seems correct, but the last row has a 'None' in it. In the code below, I am guessing that when p = 1, it gets out of the while loop, and then there is nothing to print, so it gives a None (?). Can someone point me in the right direction of why the None is added, and how to fix it?
See code right below and example results further down:
def collatz (p):
while p != 1:
if p % 2 ==0:
p = (p//2)
print(p)
else:
p = ((3*p) + 1)
print(p)
print ('Select a number between 1 and 10')
entry = float(input())
number = round(entry)
if number >10 or number <1:
print('Your selection must between 1 and 10. Please try again')
else:
Program = collatz(number)
print (Program)
** Example results: If I input number as 3, I get:
3
10
5
16
8
4
2
1
None