I have Youtubed,searched stack overflow and reddit for the the question and answer. Which I have found, but don't want to copy and paste the code just to get the answer but want to understand it.
Question and Answers: Making a collatz program automate the boring stuff (What I have learnt, which I thought was B.S. There are thousands of ways to answer a question with little to lots of code, surprising)
#Part 1 of The Collatz Sequence Chapter 3 practice project.
def collatz(number): #Defining the collatz function.
if number % 2 == 0:#If number is even use (number % 2 == 0)
print(number // 2)
return (number // 2) #What to return/print if number is even.
elif number % 2 == 1: #If number is odd use (number % 2 == 1)
print(3 * number + 1)
return (3 * number + 1) #What to return/print if number is odd.
#Part 2 and 3 of The Collatz Sequence Chapter 3 practice project.
print('Enter number:') #Asking the person to enter a number.
while True:
try: #To avoide non number erros.
number = int(input()) #Persons input.
except (NameError, ValueError):#To ignore the errors that occur from strings and other non integers.
print('Enter an integer:')#If person does not enter a number, ask them to.
if number == 1:
break
print('Collatz Sequence Destination Achiveid')
(Yes, there are a lot of comments, but that was just to understand where I was effing up).
From my interpretation of code. I am screwing up where I am under section 2. I am having difficulty linking the user input into Collatz and the while loop but believe I have already done with "number = int(input())?. My code is also not initiating the Collatz sequence I have no idea why? maybe it's not linking to it. I also want to have it, if the person enters 1, it prints xyz after break and have used break to exist the loop if 1 is entered.
Am what I am doing right? I really liked this book upto this point and it's usually highly recommended. I have also read many Reddit threads were people have recommend other books such as python crash course. Would that book be better?. I don't think I am that dumb and understand the concepts and know how use them but this practice project is making me feel otherwise and many others have mentioned the same on threads.
*To whom ever is answering this, please try to nuke it down for me and where I went wrong or be open for me to ask question, thanks.