Using python
Print out the subset of the string defined by the two integer
parameters
in a descriptive string by using string formatting.
Arguments:
a string : the string can be of any length
two integers : the integers can be positive or negative
Note: it can be assumed that the two parameters will be valid
indices
in the string
Return:
None
>>> stringFormatting("Cookies are delicious", 3, 5)
prints the line : "The characters in positions 3 to 5 of the string
are 'kie'"
>>> stringFormatting("Cookies are delicious", 6, -2)
prints the line : "The characters in positions 6 to -2 of the
string are
's are deliciou'"
def stringFormatting(string, n1, n2):
"""
Print out the subset of the string defined by the two integer parameters
in a descriptive string by using string formatting.
Arguments:
a string : the string can be of any length
two integers : the integers can be positive or negative
Note: it can be assumed that the two parameters will be valid indices
in the string
Return:
None
"""
print("The characters in positions {} to {} of the string are '{}'".format(n1, n2, string[n1:n2 + 1]))
Using python Print out the subset of the string defined by the two integer parameters in...
Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...
Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...
Python
1 Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. 3 To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Using Python, write a function recur, which on input a positive integer n retuns the value Bn defined as follows. You can assume that the function is only called with positive integer arguments. B1 = 5, B2 = 4 B2 = Bn-1* Bn-2 if n is divisible by 3 B3 = Bn-1 + Bn-2 otherwise *Please go step by step with explanation*
With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...
Python 3
Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list of strings. All of the strings in the list are keys to the dictionary. Complete the function such that it returns the subset of the dictionary defined by the keys in the list of strings. For example, with the dictionary ("puffin": 5, "corgi": 2, "three": 3) and the list ("three", "corgi"), your function should return {"corgi": 2, "three"...
1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...
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...
Write a program in python using lists or tuples that asks for two positive integers n1 and n2 and prints out all the numbers that are divisible by 7 but are not a multiple of 5 within the range [n1,n2] (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.