Skip to content

Added Few Simple Programs #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions 3 Palindrome (Question F).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def palcheck(s):
ns=""
for i in s:
ns=i+ns
if s==ns:
return True
return False

def cod(s):
l=len(s)
for i in range(2,l):
if palcheck(s[:i]):
t1=s[:i]
k=s[i:]
break
t=len(k)
for j in range(0,t):
if palcheck(k[:j]):
t2=k[:j]
k2=k[j:]
if palcheck(k2)==True:
print(t1)
print(t2)
print(k2)
else:
print("Impossible")

us=input("Input String\n")
if len(us)>=1 and len(us)<=1000:
cod(us)
else:
print("Not Under Limitation")

68 changes: 68 additions & 0 deletions 3 Palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Here are all the installs and imports you will need for your word cloud script and uploader widget

!pip install wordcloud
!pip install fileupload
!pip install ipywidgets
!jupyter nbextension install --py --user fileupload
!jupyter nbextension enable --py fileupload

import wordcloud
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import display
import fileupload
import io
import sys

# This is the uploader widget

def _upload():

_upload_widget = fileupload.FileUploadWidget()

def _cb(change):
global file_contents
decoded = io.StringIO(change['owner'].data.decode('utf-8'))
filename = change['owner'].filename
print('Uploaded `{}` ({:.2f} kB)'.format(
filename, len(decoded.read()) / 2 **10))
file_contents = decoded.getvalue()

_upload_widget.observe(_cb, names='data')
display(_upload_widget)

_upload()


def calculate_frequencies(file_contents):
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his", "her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are", "was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with", "from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no", "nor", "too", "very", "can", "will", "just"]
dic={}
f=file_contents.split(" ")
for i in f:
if ((i not in uninteresting_words) and (i.isalpha()==True) and (i not in punctuations)):
if i not in dic:
dic[i]=0
dic[i]+=1




# LEARNER CODE START HERE

#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies(dic)
return cloud.to_array()

# Display your wordcloud image

myimage = calculate_frequencies(file_contents)
plt.imshow(myimage, interpolation = 'nearest')
plt.axis('off')
plt.show()
76 changes: 76 additions & 0 deletions String Pair (Question D).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
def countvol(s):
v="aeiou"
c=0
for i in s:
if i in v:
c=c+1
return c

def work(n,e):
no=['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety','hundred']
pair=[]
p=0
k=0
for i in e:
s=int(i)
if s>=0 and s<=20:
t=countvol(no[s])
elif s>20 and s<30:
t=countvol(no[20])+countvol(no[int(i[1])])
elif s>=30 and s<40:
t=countvol(no[21])+countvol(no[int(i[1])])
elif s>=40 and s<50:
t=countvol(no[22])+countvol(no[int(i[1])])
elif s>=50 and s<60:
t=countvol(no[23])+countvol(no[int(i[1])])
elif s>=60 and s<70:
t=countvol(no[24])+countvol(no[int(i[1])])
elif s>=70 and s<80:
t=countvol(no[25])+countvol(no[int(i[1])])
elif s>=80 and s<90:
t=countvol(no[26])+countvol(no[int(i[1])])
elif s>=90 and s<100:
t=countvol(no[27])+countvol(no[int(i[1])])
elif s==100:
t=countvol(no[28])
k=k+t
for r in e:
for c in e:
if ([r,c] not in pair) and ([c,r] not in pair):
pair.append([r,c])
for r in pair:
if (int(r[0])+int(r[1])==k):
p=p+1
if p>=0 and p<=20:
print(no[p])
elif p>20 and p<30:
print(no[20]+int(no[(str(p)[1])]))
elif p>=30 and p<40:
print(no[21]+int(no[(str(p)[1])]))
elif p>=40 and p<50:
print(no[22]+int(no[(str(p)[1])]))
elif p>=50 and p<60:
print(no[23]+int(no[(str(p)[1])]))
elif p>=60 and p<70:
print(no[24]+int(no[(str(p)[1])]))
elif p>=70 and p<80:
print(no[25]+int(no[(str(p)[1])]))
elif p>=80 and p<90:
print(no[26]+int(no[(str(p)[1])]))
elif p>=90 and p<100:
print(no[27]+int(no[(str(p)[1])]))
elif p==100:
print(no[28])
elif p>100:
print("Greater Than Hundred")



n1=int(input("Number of elements\n"))
n2=input("Enter n elements followed by space")
e1=n2.split()
work(n1,e1)