Solution Python Programs
Solution Python Programs
Solution Python Programs
1.Write a python program that repeatedly asks user for their age and a password until they
provide valid input[age is in digit and password in alphabet and digit only]
#password and age validation
Input : Java
Output : jAVA
s2=''
for ch in s1:
if ch.isupper():
s2=s2 + ch.lower()
else:
s2=s2 + ch.upper()
OUTPUT
3. Develop a python code to determine whether the given string is a palindrome (OR) not
rev=''
for ch in s1:
rev=ch+rev
if s1==rev:
print('it is palindrome')
else:
OUTPUT
it is not a palindrome
it is palindrome
4. Write a program to accept the string and display total number of alphabets
count=0
for ch in s1:
if ch.isalpha():
count = count + 1
output
5. Develop a program to sort the contents to a text file and write the sorted contents in to a separate
text file
myList = infile.readlines()
lineList = []
lineList.append(line.strip())
lineList.sort()
outfile.write(line + "\n")
Content of example.txt
Contents of sorted.txt
txt = infile.read()
infile.close()
example.txt contains
it is object oriented
output
it is object oriented
7. Develop a program to find the total size of all the files in the given directory
import os
totalsize=0
invite.txt - 70 bytes
output
f=open('sample.txt', 'r')
text = f.read()
print(text)
words = text.split()
count=0
for w in words:
count =count + 1
Contents of sample.txt
Output