the collatz func in automate boring stuff with python

the collatz func in automate boring stuff with python

By : user3100273
Date : January 12 2021, 01:40 AM
it fixes the issue Your mistake is int(input("enter:")), because you are passing in a string into your function collatz(number), without converting it into int.
Welcome to stackoverflow, next time please include things like your expected outputs or what error you are receiving so that people can easily help you. You can read about how to ask a question here
code :

Share : facebook icon twitter icon
Making a collatz program automate the boring stuff

Making a collatz program automate the boring stuff

By : user41543
Date : March 29 2020, 07:55 AM
I wish this help you I'm trying to write a Collatz program using the guidelines from a project found at the end of chapter 3 of Automate the Boring Stuff with Python. I'm using python 3.4.0. Following is the project outline:
code :
def collatz(number):

    if number % 2 == 0:
        print(number // 2)
        return number // 2

    elif number % 2 == 1:
        result = 3 * number + 1
        return result

n = input("Give me a number: ")
while n != 1:
    n = collatz(int(n))
Give me a number: 3

Give me a number: 11
Dictionary from Automate the boring stuff with Python

Dictionary from Automate the boring stuff with Python

By : Preeti Jindal
Date : March 29 2020, 07:55 AM
like below fixes the issue This program is from "Automate the boring stuff with python". I am not able to understand, what tells the program to take "name" as Key and "bday" as Value , we can directly add key , value to dictionary
For reference:
code :
d = {}
d['Name']='1st April';
{'Name': '1st April'}
Automate the Boring Stuff Collatz Project

Automate the Boring Stuff Collatz Project

By : Mr_five
Date : March 29 2020, 07:55 AM
I wish this helpful for you The recursive case doesn't return anything, so control reaches the end of the function as the call stack resolves (Python functions implicitly return None, hence your error). Change the line:
code :
return integercheck(input())
def collatz(n):
    while n > 1:
        if n % 2 == 0:
            n //= 2
            n = 3 * n + 1

        yield n

def get_int(prompt="Enter a number: ", 
            err="Error: Input needs to be a number."):
    while True:
            return int(input(prompt))
        except ValueError:

if __name__ == "__main__":
    for step in collatz(get_int()):
Automate the boring stuff with Python: Mad Libs

Automate the boring stuff with Python: Mad Libs

By : user3726205
Date : March 29 2020, 07:55 AM
To fix this issue The problem in your code is that you are not checking your return values.
code :
for i in range(amount):
        if result == 'NOUN':
            print('Enter a noun:')
            k = input()
            mad_regex.sub(k, content, 1)
            content = mad_regex.sub(k, content, 1)
            search = mad_regex.search(content)  # This returns None when it doesn't match
            result = search.group() # Search is now None, and you get your exception
python - a collatz program automate the boring stuff

python - a collatz program automate the boring stuff

By : Abhik De
Date : March 29 2020, 07:55 AM
like below fixes the issue You are not updating number in your while loop so you are stuck in an infinite loop.
You should assign return value of collatz to number back, to update number.
Related Posts Related Posts :
  • Tuning the hyperparameter with gridsearch results in overfitting
  • some coordinates that I extracted from geocoder in Python are not saving in the variable I created
  • 7C in cs circles- python Im not sure what is wrong with this yet
  • How to fix 'AttributeError: 'list' object has no attribute 'shape'' error in python with Tensorflow / Keras when loading
  • python - thread`s target is a method of an object
  • Retrieve Variable From Class
  • What is the reason for matplotlib for printing labels multiple times?
  • Why would people use ThreadPoolExecutor instead of direct function call?
  • When clear_widgets is called, it doesnt remove screens in ScreenManager
  • Python can't import function
  • Pieces doesn't stack after one loop on my connect4
  • How to change font size of all .docx document with python-docx
  • How to store a word with # in .cfg file
  • How to append dictionaries to a dictionary?
  • How can I scrape text within paragraph tag with some other tags then within the paragraph text?
  • Custom entity ruler with SpaCy did not return a match
  • Logging with two handlers - one to file and one to stderr
  • How to do pivot_table in dask with aggfunc 'min'?
  • This for loop displays only the last entry of the student record
  • How to split a string by a specific pattern in number of characters?
  • Python 3: how to scrape research results from a website using CSFR?
  • Setting the scoring parameter of RandomizedSeachCV to r2
  • How to send alert or message from view.py to template?
  • How to add qml ScatterSeries to existing qml defined ChartView?
  • Django + tox: Apps aren't loaded yet
  • My css and images arent showing in django
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org