DEV Community

Abishek
Abishek

Posted on

String Problems

Password generator

import random

Upper ="ABCDEFGHEJKLMNPOQRSTUVWXYZ"
lower = "abcdefghejklmnpoqrstuvwxyz"
number = "0123456789"
special = r"""!@#$%^&*()_+-=[]|\:;"'<>,.?/"""
result=""

i=0
while i<3:
    result+=Upper[random.randint(0,25)]
    result+=lower[random.randint(0,25)]
    result+=number[random.randint(0,9)]
    result+=special[random.randint(0,27)]


    i+=1

print(result)

Enter fullscreen mode Exit fullscreen mode

Output
Cv7?Rq2'Fk8|

Password Validator program

password = "Abc@1234"

uppercase = 0
uppercaseFlag = False

lowercase=0
lowercaseFlag= False


digit=0
digitFlag =False

special=0
specialFlag=False

space=0
spaceFlag = True




if len(password)<8:
    print("Minimum length")
    exit()

i=0
while i<len(password):

    if 'A' <= password[i] <= 'Z':
        uppercaseFlag=True

    if 'a' <= password[i] <= 'z':
        lowercaseFlag=True

    if '0' <= password[i] <= '9':
        digitFlag = True

    if password[i] == ' ':
        spaceFlag=False

    if 'A' <= password[i] <= 'Z' or 'a' <= password[i] <= 'z' or '0' <= password[i] <= '9' or password[i] == ' ':
        pass
    else:
        specialFlag=True

    i+=1

if uppercaseFlag and lowercaseFlag and digitFlag and specialFlag and spaceFlag :
    print("Strong Validation")
else:
    print("check the password")
Enter fullscreen mode Exit fullscreen mode

Output
Strong Validation

Count Of Letter,Special Character and Number

sen ="Life is Good@ dream123"
letter=0
number=0
special=0

i=0
while i<len(sen):
    if (sen[i]>='A' and sen[i]<='Z')or(sen[i]>='a' and sen[i]<='z'):  
      letter+=1
    elif sen[i]>='0' and sen[i]<='9':
       number+=1
    elif sen[i] == ' ':  # ' ' is a whitespace character
       pass              
    else:
       special+=1

    i+=1


print("count of letter :",letter)
print("count of numbers :",number)
print("count of special :",special)
Enter fullscreen mode Exit fullscreen mode

Output
count of letter : 15
count of numbers : 3
count of special : 1

Upper to Lower

sen = "LIFE IS GOOD"

i=0
while i<len(sen):
   if sen[i]>='A' and sen[i]<='Z':  #this convert Upper to lower
      print(chr(ord(sen[i]) + 32), end="")
   elif sen[i]>='a' and sen[i]<='z':
      print(chr(ord(sen[i]) - 32), end="")  #this convert smaller to upper
   elif sen[i] == ' ':
      print(' ',end="")
   i+=1

print('')
Enter fullscreen mode Exit fullscreen mode

Output
life is good

Top comments (0)