Question

Write a function in python this program must also include line comments and validate def repeat(string,...

Write a function in python this program must also include line comments and validate

def repeat(string, n, delim)

that returns the string string repeated n times, separated by the string delim.

For example, repeat("ho", 3,",") returns "ho, ho, ho".

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def repeat(string, n, delim):
    result = ''  # to hold result
    for i in range(n):  # iterate n times
        result += string  # add string to result
        if i != n - 1:  # if it's not last time
            result += delim  # add delimiter to result
    return result


print(repeat("ho", 3, ", "))

Add a comment
Know the answer?
Add Answer to:
Write a function in python this program must also include line comments and validate def repeat(string,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions...

    Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. ​ For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...

  • Python Write a program which reads in a string and an signifying the number times the...

    Python Write a program which reads in a string and an signifying the number times the string should be repeated. The program should then output the string N times. integer N, You can assume all input will be valid. Example: Enter a string: hello How many times to repeat? 5 hello hello hello hello hello Example: T Enter a string: goodbye Ty How many times to repeat? 32 goodbye goodbye [... goodbye 30 more times]

  • in python Write a function that takes a string as an argument returns a new string...

    in python Write a function that takes a string as an argument returns a new string that is that string repeated 3 times.

  • Python Program 5. Write a Python program in a file named validTime.py. Include a function named...

    Python Program 5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...

  • Program must be in Python 3. Write a program that prompts the user to enter two...

    Program must be in Python 3. Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...

  • Write the code in python programming Language String Statistics: Write a program that reads a string...

    Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...

  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise (Occurrences of a specified character) Write a function...

  • How do I write a one-line (excluding function definition) python function make_filter(limit), which takes in an...

    How do I write a one-line (excluding function definition) python function make_filter(limit), which takes in an integer limit, and returns a function that takes in a list of strings, and returns a copy of the list with all strings shorter than limit characters removed. make_filter must be exactly one line of Python code, not including the function signature line ( def make_filter(limit): ) example: >>> filter5 = make_filter(5) >>> filter5(['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa']) ['aaaaa', 'aaaaaa'] >>> filter2...

  • Python 3: Write a function called every_other_character() that takes in a string and returns a new...

    Python 3: Write a function called every_other_character() that takes in a string and returns a new string with every other character removed. That is, the new string will include the first, third, fifth, etc. letters of the given string. Must use a while or for loop in the solution.

  • Write a function that would accept a string and checks if any character is repeated more...

    Write a function that would accept a string and checks if any character is repeated more than once. The function would return the repeated chars and the number of times they are repeated. The return value is a string, all pairs separated by a comma. E.G. function(“2abc**zac22”); returns: 2=3,a=2,c=2,*=2

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT