python 1-2 week-6 and week-7 programs
python 1-2 week-6 and week-7 programs
class B :
class C ( A , B ) :
class D ( C , B ) :
pass
obj = D ( )
obj . process ( )
print ( D . mro ( ) )
Output:
This is C process
1. Write a Python code to merge two given file contents into a third file.
One.txt
two.txt
file1.py
file1 = open ('one.txt' , 'r' )
file1 . close ( )
file2 . close ( )
file3 . close ( )
# Print merge text file
file3 . close ( )
output:
2.Write a Python code to open a given file and construct a function to check for given
words present in it and display on found.
def search_str(file_name) :
search_word = input ( " Enter a word you want to search in file : " )
content = file.readlines ( )
print ( ' The search word exists in the file & available at line = ' ,content . index ( word ) )
break
else :
file . close ( )
file = open ( "search.txt" , 'w' )
file . close ( )
search_str("search.txt")
Output:
3.Write a Python code to Read text from a text file, find the word with most number of
occurrences.
Program:
count = 0
max_Count = 0
words = [ ]
string = line.lower( ).replace( ',' , ' ' ) . replace ( '.' ,' ' ) . split (" ")
for s in string :
words . append ( s )
count = 1
if ( words [ i ] == words [ j ] ) :
count = count + 1
max_Count = count
word = words [ i ]
file . close ( )