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])
Here is the completed code for this problem. Assuming the language is Python. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required. Also this method uses iterative approach. If you are looking for a recursive method, just let me know, I’ll update the code quickly.
#code
#required method def double_str(text): #creating an empty string to store the result updated = '' #looping through each character in text for c in text: #appending c to updated, twice updated += c + c #returning the updated string return updated #testing print(double_str('dog')) # ddoogg print(double_str('hello')) # hheelllloo
Write a function called double_str that takes a string argument and returns a new string that...
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 smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32
Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...
Define a function called AddEvenPosDigs(string), which takes a string (with symbols and characters) as an argument, and returns an integer. This function should add the digits of a string that are in an even position. If there are no digits, the function should return -1. As an example, the following code fragment: string = "a12b056jk"; result=AddEvenPosDigs(string); print(result) should produce the output: 8
Define a Python function named getResponse() that takes a string as its only argument and returns a new string. If the argument ends with a question mark and has an even number of characters, the function should return the string "Yes". If the argument ends with a question mark and contains an odd number of characters, the function should return the string "No". If the argument ends with an exclamation point, the function should return the string "Wow". Otherwise, the...
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.
D.1 [3] Define a function called funD1...) that receives a string and returns a new string with all the characters in the original string in an EVEN position. As an example, the following code fragment: print (funD1('abcde')) should produce the output: ace D.2 [6] Define a function funD2(...) which receives a list ist that contains single letters, single digits and single special characters and the list contains at least one element of each type). The function returns a string that...
Python: Using chr() and ord() write a function called en_crypt() that takes into input a string and returns a new encrypted version of the input string. Example: "atwOta@0202" should return "fy|TyfE5757", then write a function de_crypt() so that "fy|TyfE5757" returns "atwOta@0202"
python
1. Write a function that takes in a string and returns the string sorted For example, "cat" becomes "act", "dog" becomes "dgo" Hint: You might need to use the functions join and sorted
python Problem 3 (Palindrome) Write a function called ispalindrome(string) that takes a string (with spaces) as argument and returns True if that string (ignoring spaces) is a palindrome. A palindrome is a word or phrase that spells the same thing forwards as backwards (ignoring spaces). Your program should use a recursive process to determine the result, by comparing the first and last letters of the string, and if necessary, calling ispalindrome() on the rest of the string. Sample run: print(ispalindrome('never...