Professional Documents
Culture Documents
Alva'S Institute of Engineering & Technology
Alva'S Institute of Engineering & Technology
def palindrome(a):
mid = (len(a)-1)//2 #you can remove the -1 or you add <= sign in line
21
start = 0 #so that you can compare the middle elements also.
last = len(a)-1
flag = 0
# string
if (a[start]== a[last]):
start += 1
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
last -= 1
else:
flag = 1
break;
# or not
if flag == 0:
else:
def symmetry(a):
n = len(a)
flag = 0
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
# is odd or even
if n%2:
mid = n//2 +1
else:
mid = n//2
start1 = 0
start2 = mid
if (a[start1]== a[start2]):
start1 = start1 + 1
start2 = start2 + 1
else:
flag = 1
break
# or not
if flag == 0:
else:
# Driver code
string = 'amaama'
palindrome(string)
symmetry(string)
s = string.split()[::-1]
l = []
for i in s:
l.append(i)
print(" ".join(l))
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
3. Python program to convert the given string into Uppercase Half String.
test_str = 'geeksforgeeks'
hlf_idx = len(test_str) // 2
res = ''
res += test_str[idx].upper()
else:
res += test_str[idx]
# printing result
import re
# initializing string
# initializing word
wrd = 'best'
test_str = test_str.split()
res = -1
res = test_str.index(idx) + 1
# printing result
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
class Dog:
# Class Variable
animal = 'dog'
# Instance Variable
self.breed = breed
self.color = color
print('Rodger details:')
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
print('\nBuzo details:')
# name also
print(Dog.animal)
class GeekforGeeks:
# default constructor
def __init__(self):
self.geek = "GeekforGeeks"
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
def print_Geek(self):
print(self.geek)
obj = GeekforGeeks()
obj.print_Geek()
print (file.read(5))
file = open('geek.txt','w')
file.close()
def commonfun(str1,str2):
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
return(len((set(str1)).intersection(set(str2))))
string1="VISHAV"
string2="VANSHIKA"
no_of_common_character=commonfun(string1.lower(),string2.lower())
test_str = "GeeksforGeeks"
all_freq = {}
for i in test_str:
ALVA’S INSTITUTE OF ENGINEERING & TECHNOLOGY
(Unit of Alva’s Education Foundation (R), Moodbidri)
Affiliated to Visvesvaraya Technological University, Belagavi & Approved by AICTE, New Delhi. Recognized by Government of
Karnataka.
Accredited by NAAC with A+ Grade
Shobhavana Campus, MIJAR-574225, Moodbidri, D.K., Karnataka
Ph: 08258-262725; Mob:722262724,7026262725,mail:principalaiet08@gmail.com
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
# printing result
count = {}
count[word] = count.get(word, 0) + 1
count[word] = count.get(word, 0) + 1
# Driver Code
print(UncommonWords(A, B))