Answer:
Following are the program in the Python Programming Language:
1.)
l=['Ruby','Dale','Kate']
n=input('Enter the name: ')
if(n in l):
print('Hello {}'.format(n))
else:
print('No {}'.format(n))
Output:
Enter the name: Dale
Hello Dale
2.)
file=open("text1.txt", "r+") #open file
str=file.read() #read file
txt=str.replace('\n', ' ') #replace spaces
word=txt.split(' ') #split words in ' '
for words in word: #set for loop
word2=' '
for i in range(len(words)): #set for loop
if(words[i].isalpha()): #set if statement
word2 += words[i].lower()
word[word.index(words)]=word2
while(' ' in word): #set while loop
word.remove(' ') #remove spaces
st=set(word)
print('The ', len(st),' unique words which appears in document are ' \
'(in no particular order): ')
for words in st: #set for loop
print('-', word)
file.close() #close file
3.)
file=open("text1.txt", "r+") #open file
str=file.read() #read file
txt=str.replace('\n', ' ') #replace spaces
word=txt.split(' ') #split words in ' '
for words in word: #set for loop
word2=' '
for i in range(len(words)): #set for loop
if(words[i].isalpha()): #set if statement
word2 += words[i].lower()
word[word.index(words)]=word2
while(' ' in word): #set while loop
word.remove(' ') #remove spaces
dic={} #set dictionary
for words in word: #set for loop
if(words not in dic): #set if statement
dic[words]=1
else:
dic[words] +=1
print('\033[4m' + 'word frequency' + '\033[0m')
for words in dic:
print(format(words, '15s'), format(dic[words], '5d'))
file.close() #close file
Explanation:
1.) Here, we define the list data type variable 'l' then, set the variable 'n' and assign value by get input from the user,
- we set if conditional statement and pass condition is that the variable 'n' is in the variable l then, print message.
- otherwise, we print No message.
2.) Here, we define the variable "file" in which we open file and save that file in it.
Then, we set variable st which read the file then we set the variable in which we apply the replace().
Then. we set variable in which we split the by suing split()
2.) Here, we define the variable "file" in which we open file and save that file in it.
Then, we set variable st which read the file then we set the variable in which we apply the replace().
Then. we set variable in which we split the by suing split()
Then, we apply all that given in the question.