Apr-17-2018, 10:54 PM
Write a function named collatz() that has one parameter named number. If number is even, then collatz() should print number // 2 and return this value. If number is odd, then collatz() should print and return 3 * number + 1.
Then write a program that lets the user type in an integer and that keeps calling collatz() on that number until the function returns the value 1.
Traceback (most recent call last):
File "C:\Python36\kodovi\coll.py", line 10, in <module>
n = collatz(int(n))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Not sure why am I receiving this message.
Then write a program that lets the user type in an integer and that keeps calling collatz() on that number until the function returns the value 1.
def collatz(number): if number % 2 == 0: print(number//2) else: result = 3*number + 1 print(result) try: n = input("Give me a number: ") while n != 1: n = collatz(int(n)) except ValueError: print('Type a number please!')message:
Traceback (most recent call last):
File "C:\Python36\kodovi\coll.py", line 10, in <module>
n = collatz(int(n))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Not sure why am I receiving this message.