TypeError <= not supported between instances of 'str' and 'int' for a project

Viewed 49

Hello everybody today I was working on a piece of code that doesn't let you type a password (letters, numbers, or special characters) that is less than eight characters but I was getting the type error which is mentioned in the title. Here is the code if you would like to take a look:

password_1 = input('Type a password [8 or more characters]: ')
while len(password_1) <8:
  print(password_1)
if password_1 >= 8:
  print('The password you entered is valid')

I am a beginner at python and it would mean a ton to me if anybody can help because I think I tried everything I can.

edit: the error is in line 4.

-Thanks in advance!

1 Answers

First of all it would help if you stated what line the error was thrown in. I can only guess it is the if statement. It says if password_1 >= 8: But password_1 is a string so you cannot compare it to an integer. What you need to do is the same as in the the while loop. len(password_1) >= 8

Also I think you will have to reinitiate the input in the while loop. Otherwise it will just be stuck printing the same password you typed over and over.

Related