TypeError: ‘int’ object not callable

Question:
How do I fix this problem to make my code work?
Repl link:

https://replit.com/@SalladShooter/Password-Generator#main.py


import random
from colorama import Fore as F
from colorama import Style as S
bright = S.BRIGHT
normal = S.NORMAL
blue = F.BLUE
white = F.WHITE
green = F.LIGHTGREEN_EX
red = F.RED
yellow = F.LIGHTYELLOW_EX
purple = F.LIGHTMAGENTA_EX
light_blue = F.LIGHTBLUE_EX

print(f'How many {blue}{bright}characters {normal}{white}do you want your password to have?')
chr = int(input())

password = []

for i in range (chr):
  character = chr(random.randint(32,191))
  password.append(character)
  
print(password)

This is likely because you named your variable chr, which matches the name of the function chr().

Also, that’s a really cool way of making a password generator! Would have never thought of that.

3 Likes

Agreed! I was trying to think of a way for a password generator, and that does the job!

As said above, you have named the variable “chr” which is the same as the built in chr() function, so the variable you have is overriding the built in Python method and it thinks you are trying to call the user input that you converted to an integer, hence the error.

Welcome! But why are you restating what was already said previously?

Hey!

I just wanted to clarify that the reason why “int error is not callable” is raising, so i reiterated the previous comment and added more context as to why the error is arising :blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.