Python
Function Name:
unscramble
Parameters: a string
Returns: a string
Description: Write a function, unscramble, that
takes an input string, and returns a the unscrambled version of the
argument.
To unscramble the string:
Example Call: unscramble('3cis1') Expected result: ics31
Example Call: unscramble('ocicssol') Expected result: csiscool
def unscrample(strg):
#finds length of string
length=len(strg)
#for storing new string
unscrampleString=" "
#if length of string is odd
if(length%2==1):
#finds mid index
midIndex=int(length/2)
#store character at midindex
unscrampleString+=strg[midIndex]
#for each left and right charcters
for i in range(1,midIndex+1):
unscrampleString+=strg[midIndex-i]
unscrampleString+=strg[midIndex+i]
#if length of string is even
else:
#finds mid index
midIndex=int(length/2)
#a copy of mid index
newMidIndex=midIndex
#for each left and right charcters
for i in range(1,midIndex+1):
unscrampleString+=strg[midIndex-i]
unscrampleString+=strg[newMidIndex]
#increment for next character
newMidIndex+=1
return unscrampleString
print(unscrample('3cis1'))
print(unscrample('ocicssol'))
Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that...
Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...
Function Name: zip_d Parameters: two equal-sized lists Returns: a dictionary Description: Write a function, zip_d, that takes a two equal-sized lists as parameters, and zips each list into a dictionary. Sample Inputs/Outputs: Example Call: zip_d([1,2,3], ['a','b','c']) Expected Return: {1: 'a', 2: 'b', 3: 'c'} Example Call: zip_d([‘a’,’b’,’c’],[9.8,7.6,5.4]) Expected Return: {‘a’:9.8, ’b’:7.6, ’c’:5.4} please answer in python
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 Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should be posted every mile on a given street. You are given a list of 0s & 1s, where each number represents a quarter of a mile. Thus, every 4 zeroes requires a speed sign. However, a 1 indicates an intersection, and each intersection is automatically required to have a speed limit sign. A sign for each mile proceeds as usual after the intersection. Your...
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 python function that takes a string as input, and returns a dictionary of frequencies of all the characters in the string. For example: freq("dabcabcdbbcd") would return {"d":3, "a":2, "b":4, "c":3}. Then write a driver to demonstrate your function.
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])
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...
Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...
pYTHON Exercise: create01 Description Write a function that receives no parameters and returns a Pencil object constructed with 3 leads. Function Name create01 Parameters • None Return Value A Pencil object with 3 leads. Example р create01() print(p.get_num_leads()) # -> 3 print(p.get_current_lead_length()) # > 10 Hints • Don't forget to import Pencil.