typeerror

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

Python TypeError: 'tuple' object is not callable when using list comprehension inside for loop

Python TypeError: 'tuple' object is not callable when using list comprehension inside for loop Question: I’m trying to generate a list of strings using a list comprehension, where the string is formatted using f-strings: features = [("month", (1, 12)), ("day_of_year", (1, 365))] for feature, range in features: cols= [f"transformed_{feature}_period_{i:02d}" for i in range(12)] If I …

Total answers: 2

Decorator causing my function to not accept positional argument?

Decorator causing my function to not accept positional argument? Question: I am learning how to use decorators. Inspired by tqdm library (progress bars), I have cobbled together a decorator, heavily inspired by this code. The goal is to use multithreading to have a progress indicator blink/spin/count in stdout while a long-running function that does not …

Total answers: 2

i have Error codes when running my python program

i have Error codes when running my python program Question: I have this python script that calculates the factorial of number. import math def calculate_factorial(n): if n < 0: return 0 elif n == 0: return 1 else: return n * calculate_factorial(n – 1) def main(): n = input("Enter a number: ") factorial = calculate_factorial(n) …

Total answers: 1

not all arguments converted during string formatting (while passing arguments to function)

not all arguments converted during string formatting (while passing arguments to function) Question: I am getting error "not all arguments converted during string formatting" while running this code please explain how to fix this and what is this error def multiples(l,n): count=0 for i in l: if(i%n==0): count+=1 return count m=input("no of elements: ") l=[] …

Total answers: 1

Python function to count divisible numbers in a list?

Python function to count divisible numbers in a list? Question: I need to write a python function that takes a list as the input and calculates the number of numbers divisible by some other number, n. This is the code I have so far: enter image description here Could someone advice me on what approach …

Total answers: 2

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

Error: TypeError: 'list' object is not callable Using turtle graphics

Error: TypeError: 'list' object is not callable Using turtle graphics Question: I am attempting to code space invaders. I am doing some finishing touches however when trying to create three hearts in the top corner to represent lives I have this error: TypeError: ‘list’ object is not callable The relevant code in main.py is: from …

Total answers: 1

Why am I seeing "TypeError: string indices must be integers" in this situation?

Why am I seeing "TypeError: string indices must be integers" in this situation? Question: im trying to predict stock market movement but in the start i’m stuck in this error: "TypeError: string indices must be integers" the code that i have problem with is: import pandas_datareader as web df = web.DataReader(‘AAPL’, data_source=’yahoo’, start=’2012-01-01′, end=’2019-12-17′) TypeError: …

Total answers: 1