Class program

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

< So i am working on this code for class and for some reason i cant get the if statement to return true. Those parameters are, must be exactly 6 digits, The first and last digits must be numbers. The premise of this is that i am making a password encryptor so the last part is just that(python). .>

<What do you expect to happen instead?>

```python

“”“This is a code that is supposed to make sure user enters a valid “password” (six digits, the first and last digits have to be numbers) after the the code has to output an the password but encoded”""
password = raw_input (“Enter your password”)
str = password
if (password) == 6 and (password[0]).isdigit and (password[5]).isdigit and not (password[1-4]).isdigit:
str = password;
print str.replace (“1”,")").replace (“2”,"(").replace (“3”,"*").replace (“4”,"&").replace (“5”,"^").replace (“6”,"%").replace (“7”,"$").replace (“8”,"#").replace (“0”,"!").replace (“9”,"@")
else:
print “You did not a password that meets requirements”

<do not remove the three backticks above>

Propably silly suggestion, I don’t have much of an idea, I don’t even know what language you are using so I don’t know the exact syntax, but maybe with the way it is written you check if the input equals 6 and not the lenght of the string equals 6?

Python, by the way. You raise a good point…

if len(password) ...

This is not a valid slice. Indices are separated by colons. Consider,

>>> pwd = "bridge"
>>> pwd[1-4]
'd'
>>>

This wasn’t a range, but literally index[-3] which from right to left gives 'd'.

>>> pwd[1:5]
'ridg'
>>>
1 Like

I have taken into account both of your suggestions, I added len before password (len(password) == 6) also i switched the “-” to a “:” (and not (password[1:4]).isdigit:) but it’s still not true where it should be after the if statement.

i figured out how to fix the problem thanks for the other help though you guys!

1 Like