Question

def zigzag(text): Implement a function that takes a string and returns a new string that is...

def zigzag(text): Implement a function that takes a string and returns a new string that is a zig-zag rearrangement of it like the one in the examples below. • Parameters: text is a string (no validation needed) • Examples: zigzag('12345678') → '18273645'

zigzag('123456789') → '192837465'

zigzag('abcdefgh') → 'ahbgcfde'

zigzag('GeorgeMason') → 'GneoosragMe'

in python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def zigzag(text):
n=len(text)
l=0;
h=n-1;
st=""
while(l<h):
st=st+text[l]+text[h]
l=l+1
h=h-1
if(n%2!=0):
st=st+text[l]
return st
  
print(zigzag('GeorgeMason'))

Add a comment
Know the answer?
Add Answer to:
def zigzag(text): Implement a function that takes a string and returns a new string that is...
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
  • def zigzag(text): Implement a function that takes a string and returns a new string that is...

    def zigzag(text): Implement a function that takes a string and returns a new string that is a zig-zag rearrangement of it like the one in the examples below. • Parameters: text is a string (no validation needed) • Examples: zigzag('12345678') → '18273645' zigzag('123456789') → '192837465' zigzag('abcdefgh') → 'ahbgcfde' zigzag('GeorgeMason') → 'GneoosragMe' Remember, do not call input() or print()  You must have at least one loop in each function. You cannot import any module. You cannot call any Python function...

  • Write a function that takes a string as a parameter and returns a new string that...

    Write a function that takes a string as a parameter and returns a new string that is the reverse of the old string. Python from test import testEqual def reverse(s): return s testEqual(reverse("hello"),"olleh") testEqual(reverse("l"),"l") testEqual(reverse("follow"),"wollof") testEqual(reverse(""),"")

  • 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.

  • Write a function called double_str that takes a string argument and returns a new string that...

    Write a function called double_str that takes a string argument and returns a new string that has all of the same characters as the argument, except each one is repeated twice. For example: double_str('dog') --> 'ddoogg' looking for python coding below is what I have so far double_str = 'robert' double_str 'robert' for i in range(len(double_str)): print(double_str[i])

  • Implement a function ion2e() that takes a string as a parameter. If the string ends with...

    Implement a function ion2e() that takes a string as a parameter. If the string ends with 'ion' it returns the initial part of the string (before the 'ion') followed by an 'e' with no extra spaces. If the string does not end with 'ion', including the circumstance in which the string contains 'ion' as a substring, it returns the original string. The following shows several examples of how the function would be used: ion2e('congratulation') congratulate ion2e('marathon') marathon ion2e('hyperrational') hyperrational ion2e('irradiation')...

  • 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.

  • (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...

    (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...

  • PYTHON The function longest that returns the longest of two strings. The function count_over that takes...

    PYTHON The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...

  • def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have...

    def sum_gt_avg(num_list): Implement a function that returns the sum of the numbers in num_list that have a value greater than the average value in the list. • Parameters: num_list is a list of numbers (mixed integers and floats) • Examples: sum_gt_avg([1,2,3,4,5]) → 9 # 4+5 sum_gt_avg([1,2,3,-4,5]) → 10 # 2+3+5 sum_gt_avg([-1,-2,-3,-4,-5]) → -3 # -1-2

  • Implement a Python function called revd that takes a chain of characters and returns a new...

    Implement a Python function called revd that takes a chain of characters and returns a new chain with the double of the elements but in reverse order. In the main program, ask the user to input the chain of characters, call the function and display the result Example : Please enter a chain of characters: abcd ddccbbaa NOTE: This is a repost. Please DO NOT use GLOBAL Variables

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