Write a python programme that defines a function and calls it to print “---------------------" lines followed by the text “Congratulations” + concatenated with the name of any person taken as parameter passed to the function + text “you passed the examination!”.
# underline() function
# Parameter: filen name
def underline(file_name):
# Opening file in the read mode
with open(file_name, 'r') as fp:
for line in fp:
# Spliting line into words
for word in line.split():
# If word starts with a '.'(period)
if word[0] == '.':
# Print word without '.'
print(word[1:])
# Print a line of dashes and commas equal in length of the word
print(''.join(['_' if i%2==0 else ',' for i in range(len(word)-1)]), end='')
print()
# Otherwise, print the word
else:
print(word)
# Calling underline() function by passing "input.txt" file name as parameter
underline("input.txt")
Comments
Leave a comment