-7

I know this was already asked by other person but i never understood the code and i guess this one is a bit different. So i need a code in my python program that removes 5 points from the variable "points". For example: if password is qwert123 then there are 3 combinations "qwe", 'wer',"ert" and 15 points are removed. Please help me, i need it in a simplest language as possible so i could understand it. Thank you a lot!

    user_password = input()
    password = int(len(user_password))
Bravewave
  • 69
  • 1
  • 10
Alim Alim
  • 1
  • 3

1 Answers1

1

A solution to this problem can be found here.

Adapting it to the problem at hand, the following code will do what you require:

qwertyKeyboard = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
user_password = input("enter password")
points = len(user_password)

def chunkstring(string):
    return (string[0+i:3+i] for i in range(0, len(string)))

for chunk in list(chunkstring(user_password)):
    if len(chunk) == 3:
        if chunk in qwertyKeyboard[0] or chunk in qwertyKeyboard[1] or chunk in qwertyKeyboard[2]:
            print(chunk)
            points -= 5

print(points)

The chunkstring function breaks the password up into chunks of characters, which are then checked by the for loop against the qwertyKeyboard list, and deducts 5 points from the points variable for each set three consecutive characters that are found.

Bravewave
  • 69
  • 1
  • 10