Question

Using python Print out the subset of the string defined by the two integer parameters in...

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'"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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]))
Add a comment
Know the answer?
Add Answer to:
Using python Print out the subset of the string defined by the two integer parameters in...
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
  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

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

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

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

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

  • Python 1 Write a function called sum_odd that takes two parameters, then calculates and returns the...

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

  • Using Python, write a function recur, which on input a positive integer n retuns the value...

    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*

  • Python 3 Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys)...

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

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

  • PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

    PYTHON 4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function. 5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt"). 6. Ask the user for 5...

  • Write a program in python using lists or tuples that asks for two positive integers n1...

    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.

  • Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks....

    Using C++ Write two `void` functions.  These functions each take two  integer parameters.  The functions accomplish the following tasks. The first function prints out the numbers from the first argument up to and including the number passed as the second argument counting by the first argument (i.e. if the arguments are 2 and 10, the information below was given: #include <iostream> using namespace std; // function definitions// // main program int main() {   int firstNumber,secondNumber;   char countType, doAgain;   // we will do this...

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
ADVERTISEMENT