Assignment 2
Assignment 2
Algorithm:
Source Code:
name=input("Enter Name:")
a=name.split(" ")
b=""
for i in range(len(a)-1):
b=b+a[i][0].upper()+'.'
b=b+a[-1][0].upper()+a[-1][1:]
print(b)
Output:
Set-1:
Enter Name: Supriyo John Roy
S.J.Roy
Set-2:
Enter Name: Aksh Kumar Shah
A.K.Shah
Set-3:
Enter Name:Kunal Pramanik
K.Pramanik
Date:
Algorithm:
Source Code:
str=input("Enter a String:")
s=""
b=len(str)
for i in range(0,b):
if(str[i].islower()):
s=s+str[i].upper()
elif(str[i].isupper()):
s=s+str[i].lower()
else:
s=s+str[i]
print("The new string is=",s)
Date:
Output:
Set-1:
Enter a String:Akash Kumar
The new string is= aKASH kUMAR
Set-2:
Set-3:
Algorithm:
1. Enter a string and store it in a variable
2. Run a loop in the iteration of (i) between (len(a)-1,-1,-1)
3. Find the reverse of the string
4. Now using the if statement check if the reverse order string is same as the
given string i.e. if the string is palindrome or not
5. Print the string is palindrome or not
Source Code :
a=input("Enter a string:")
w=""
for i in range(len(a)-1,-1,-1):
w=w+a[i]
print(w)
if(w==a):
print("It is pallindrome string")
else:
print("It is not a pallindrome string")
Date:
Output:
Set-1:
Enter a name:eye
eye
It is pallindrome string
Set-2:
Enter a name:level
level
It is pallindrome string
Set-3:
Enter a name:Kunal
lanuK
Algorithm:
1. Enter a sentence and split the string into a list
2. Traverse the list till the length of the string
3. Run a loop in the iteration of (i) between(0,len(string))
4. Convert the given string to uppercase
5. Using the if statement, check if the first letter of each word in the sentence
is vowel i.e.(A,E,I,O,U)
6. Print the list
Source Code:
k=input("Enter a Sentence :")
p=k.split(" ")
for i in range(len(p)):
m=p[i][0]
n=m.upper()
print(p[i][0:])
else:
Output:
Set-1:
Enter a Sentence :Higher Algebra Abstract and Linear
Algebra
Abstract
And
Set-2:
Enter a Sentence :Kunal like to wear dennin shirt
no such word
Set-3:
Enter a Sentence :Akash lives in Odisha
Akash
in
Odisha
Date:
Algorithm:
1. Enter a string from the user and store it in a variable.
2. Initialize vowels,digits,words,alphabets variables to 0.
3. Use a for loop to traverse through the characters in the string.
4. Use an if statement to check if the character is a vowel or digits or not and
increment the vowel variable or digit variable if it is a vowel or digit.
5. Print no of alphabets , no of words,no of vowels and no of digits in the
string.
Source Code:
chr= input("Enter the string : ")
v= 0
d= 0
a= 0
w= 0
chr = chr.upper()
l= chr.split()
v = v + 1
Date:
d = d + 1
for i in range(0,len(chr)):
a = a + 1
Output:
Set-1:
Enter the string : Kunal loves SCC56
Set-2:
Enter the string : I love to see movies
Set-3:
Enter the string : Life is too short to live
Algorithm:
1. Enter a sentence
Source Code :
w=[]
if word==word[::-1]:
w.append(word)
Output :
Set-1:
Enter a sentence: Her eye is so attractive
Set-2:
Enter a sentence: MB mam is so good
Set-3:
Enter a sentence: I refer to her