1. Given string to 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)
Output
2. First letter to 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)
Output
3. Letter 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)
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)
Output
5. Password Validator
text=input("Enter 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 len(text)>=8 and upper and lower and number and special and others:
print("Valid Password")
else:
print("Invalid Password")
Output
6. 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)
Output






Top comments (0)