integer

Why 00 is a valid integer in Python?

Why 00 is a valid integer in Python? Question: In the Python documentation : integer ::= decinteger | bininteger | octinteger | hexinteger decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] "0")* bininteger ::= "0" ("b" | "B") (["_"] bindigit)+ octinteger ::= "0" ("o" | "O") (["_"] octdigit)+ hexinteger ::= "0" ("x" | "X") (["_"] …

Total answers: 1

How would I increase a integer value inside this loop?

How would I increase a integer value inside this loop? Question: Trying to increase an integer value So basically I’m trying to increase "e" so everytime I input a new line it would go 0, 1 etc My input would look like this example1 example2 def no(paths: str): e = 0 for path in paths.split(" …

Total answers: 3

How to filter elements in a list that occur only once

How to filter elements in a list that occur only once Question: I need to filter and discard elements in a list that occur only once. I have the following list of integers as input. I need to make a new list that contains only elements that do not have singular appearances. item_list = [502, …

Total answers: 2

Getting error when I run my program. What do I need to change?

Getting error when I run my program. What do I need to change? Question: import random, string characters = string.ascii_letters + string.digits + string.punctuation def generate_random_password(): length = int(input("How many characters in password? ")) number_of_passwords = int(input("How many passwords would you like? ")) character_count = characters if character_count > str(length): print("To long, try again") return …

Total answers: 2

how to loop through a list of integers

how to loop through a list of integers Question: I’m trying to loop through a list of integers by using a for loop. However, we know that in python, int is not iterable. So I’m wondering if there’s any ways I can store integers in another way so that I can loop through the integers? …

Total answers: 5

st_ino from os.stat in Python gets unexpectedly altered if output to a file

st_ino from os.stat in Python gets unexpectedly altered if output to a file Question: I have tried to research this to see if it is expected behavior or not but I haven’t found anything. Maybe I’m not using the right search terms. I use os.stat in Python and capture file attributes but I have noticed …

Total answers: 1

Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print(name + age) TypeError: can only concatenate str (not "int") to str

Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> print(name + age) TypeError: can only concatenate str (not "int") to str Question: I was writing the above code when I encountered an error can you help me? name = ‘mahbod’ age = 12 print(name + age) Traceback (most recent call last): File "<pyshell#2>", …

Total answers: 1

If/else stops after a few statements

If/else stops after a few statements Question: I am trying to create and if/elseif statement so that when user inputs a number it gives him the answer of how many integers he has. message = int(input("Enter an integer:")) if message < 0: print("1 digit, negative") elif message < 10: print("1 digit") elif message >= 10: …

Total answers: 1

Transform string to integer/float/numeric not working Python

Transform string to integer/float/numeric not working Python Question: I have a string i = ‘0, 1, 1, 0, 1, 1’ For some reason I cannot turn it into a numeric/float/integer. Depending on the way I try it, I get errors like: AttributeError: ‘str’ object has no attribute ‘to_numeric’ AttributeError: ‘str’ object has no attribute ‘astype’ …

Total answers: 1

TypeError: int() argument must be a string, a bytes-like object or a number, not 'set'

TypeError: int() argument must be a string, a bytes-like object or a number, not 'set' Question: api_key = ‘2323’ n_page = ‘1’ params = { ‘api_key’: {api_key}, ‘start_page’ : {n_page}, } params[‘start_page’] = str(int(params[‘start_page’]) + 10) I get this error considering in the last line: TypeError: int() argument must be a string, a bytes-like object …

Total answers: 1