Skip to content

Tag: python-3.x

Grouping Binary Digits in Python

I have a binary number, how can I group the same digits in pairs and split the number on single zero? For example: Answer You could use an iter of the string to compare the current character to the next one. If they are the same, add them to the current block; if they are different, the first one must

Load and Save Dictionary and Class Instances Python Script

Writing a python script that prompts the user by asking if they are are new or an existing user. If new, they will create a username, password, age. A User class instance should be created with that information along with adding the new username and password to the security dictionary. Once registered, or an …

Don’t understand why my function can’t be called

I try to make a little text based rpg with python. And the first thing that I want to make is an input to equip armor or weapons. So here is the problem: my function find_armor is not calling whatever I enter. If my first word is “equip” the output is always: your armor: 0 0 Answer In a function,

Collatz’s hypothesis testing in Python

I am trying to build a small program to test the collatz’s hypothesis. So far, I have the following: But when I run it, it’s going into an endless loop of 0.0s. Not really getting where the problem is. Answer As Nearoo mentioned, c0 % 2 is the same as c0 % 2 != 0 because 1 (when c0 is