Answer to Question #203579 in Electrical Engineering for sarah

Question #203579

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!”.

1
Expert's answer
2021-06-07T05:47:13-0400
# 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")




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS