DEV Community

S Sarumathi
S Sarumathi

Posted on

String Program

1.Full String Uppercase:

text=input("Enter some words :")
i=0
upper=""
while i<len(text):
    ch=text[i]
    if ch>="a" and ch<="z":
        upper=upper+chr(ord(ch) - 32)
    else:
        upper=upper+ch
    i+=1
print(upper)
Enter fullscreen mode Exit fullscreen mode

Output:

2.Firts Letter Uppercase:

text=input("Enter some words :")
i=0
upper=""
while i<len(text):
    ch=text[i]
    if (ch>="a" and ch<="z") and (text[i-1]==" " or i==0):
        upper=upper+chr(ord(ch) - 32)
    else:
        upper=upper+ch
    i+=1
print(upper)
Enter fullscreen mode Exit fullscreen mode

Output:

3.Letters Count:

text=input("Enter some words :")
i=0
count=0
while i<len(text):
    ch=text[i]
    if (ch>="a" and ch<="z") or (ch>="A" and ch<="Z"):
        count+=1
    i+=1
print(count)
Enter fullscreen mode Exit fullscreen mode

Output:

4.Word Count:

text=input("Enter some words :")
i=0
count=1
while i<len(text):
    if text[i]!=" " and text[i-1]==" ":
        count+=1
    i+=1
print(count)
Enter fullscreen mode Exit fullscreen mode

Output:

5.Password Verify:

text=input("Create your password :")
i=0
upper=False
lower=False
number=False
special=False
others=True
while i<len(text):
    ch=text[i]
    if ch>="A" and ch<="Z":
        upper=True
    elif ch>="a" and ch<="z":
        lower=True
    elif ch>="0" and ch<="9":
        number=True
    elif ch=="!" or ch=="@" or ch=="#" or ch=="$" or ch=="&":
        special=True
    else:
        others=False
    i+=1
if upper and lower and number and special and others:
    print("password succesfully create")
else:
    print("invalied try another")
Enter fullscreen mode Exit fullscreen mode

Output:

5.Password Generator:

import random

upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
special="!@#$&"

all_chars=upper+lower+numbers+special

password=""

password=password+random.choice(upper)
password=password+random.choice(lower)
password=password+random.choice(numbers)
password=password+random.choice(special)

i=4

while i<8:
    password=password+random.choice(all_chars)
    i+=1

print("Generated Password :",password)
Enter fullscreen mode Exit fullscreen mode

Output:

Top comments (0)