Pythonassi 2
Pythonassi 2
Pythonassi 2
word=0
maxcount=0
words=[]
file=open("File1.txt","r")
string=line.lower().replace("","").replace("","").split(" ")
for s in string:
words.append(s)
for i in range(0,len(words)):
count=1
for j in range(i+1,len(words)):
if(words[i]==words[j]):
count=count+1
if(count>maxcount):
maxcount=count
word=words[i]
file.close()
Output:
2. Write a recursive python program to calculate the sum of a list of a
number.
list=[]
len=int(input("Enter number of items in list:"))
for x in range(len):
temp=int(input("Enter list item:"))
list.append(temp)
def sum(copy_list,index):
if index==0:
return copy_list[index]
return copy_list[index]+sum(copy_list,index-1)
print(sum(list,len-1))
Output:
3.Write arecursive python program to calculate the sum of the positivr integers
of n+(n-2)+(n-4)…(until n-x=0).
def sum(p):
if (p-2)<=0:
return p
else:
return p+sum(p-2)
print(sum(16))
print(sum(18))
print(sum(9))
Output:
4. Write a program to check whether string is palindrome or
symmetric.
def SyMPal(string):
if string==string[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
size=len(string)
if size%2==0:
half=size//2
if string[0:half]==string[half:size]:
print("This is symmetrical")
else:
print("This is not symmetrical")
SyMPal("khokho")
Output:
1.Write a Python function to check whether a number is perfect or not from 1 to
10000.
def perfect(num):
div_sum = sum([i for i in range(1, num) if num % i == 0])
return div_sum == num