Question

This is slice operator : [i : j] (Function) Slice : Returns the substring from i...

This is slice operator :
[i : j] (Function)
Slice : Returns the substring from i to j -1

Quetion: 1) using the slice operator, print your first, then last name .
2) Print the length of your first name.
3) Assume you have two variables : s=‘s’ and p=‘p’ .
Using concatenation and repetition, write an expression that produced the string mississippi.


please attach your code and output
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer..

CODE:

name="Tony stark"
firstname=name[0:4]
lastname=name[5:]
print(firstname,lastname) #first one
print(len(firstname)) #second one
s='s'
p='p'
i='i'
result='m'+i+(s*2+i)*2+p*2+i #third one
print(result)

OUTPUT:

Lè slice.py - C:\Users\bheem007\Desktop\slice.py (3.6.3) File Edit Format Run Options Window Help name=Tony stark firstname

If you have any doubts please COMMENT...

If you understand the answer please give THUMBS UP....

Add a comment
Know the answer?
Add Answer to:
This is slice operator : [i : j] (Function) Slice : Returns the substring from i...
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
  • Using python, create a program using nested loops to write a function called substring(s,b) that returns...

    Using python, create a program using nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. For example: String: "Diamond" Substring: "mond" The code will then state that this is true and "mond" is a substring of "Diamond". Example of what the program should output: Enter string: Tree Enter substring: Tre Yes, 'Tre' is a substring of 'Tree' Limitation: This program cannot use "find()" and "in"...

  • 2. Prove that abSearch returns ?1 if str does not contain “ab” as a substring. You...

    2. Prove that abSearch returns ?1 if str does not contain “ab” as a substring. You may omit the base case for this proof (done in problem 1). Hint: you will need to think carefully about the different cases of the if statement in lines 15–23 to show that abSearch always returns ?1 when str doesn’t contain “ab.” Answer the following questions about the algorithm below, which searches an input string for the substring "ab" and returns where "ab" first...

  • anyString.substr(x, n) - Returns a copy of a substring. The substring is n characters long and...

    anyString.substr(x, n) - Returns a copy of a substring. The substring is n characters long and begins at position x of anyString. Write a program that reads a string from the user containing a date in the format mm/dd/yyyy. You have to use above substring method to extract the various fields from the format. It should print the date in the form Month Date, Year. Validate:  Exit the program with error message as “Invalid date format” if length of...

  • Hello, I'm having trouble with this certain part to a project of mine. Say I have...

    Hello, I'm having trouble with this certain part to a project of mine. Say I have two strings, String left and String right. This is part of an expression evaluation problem, and I need to have a certain piece of the expression in left and a certain piece of the expession in right. The code I have works with everything except if * or / come before + or -. No parentheses included, I have another method that deals with...

  • Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex...

    Assembly Language NASM create a substring ASSIGNMENT INSTRUCTIONS: Create the Substring from the Given string, beginIndex and endIndex The program should create a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex – 1. Thus the length of the substring is endIndex-beginIndex. In other words you can say that beginIndex is inclusive and endIndex is exclusive while getting the substring. Initialize the following values in...

  • Page 3 of 7 (Python) For each substring in the input string t that matches the...

    Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...

  • Deletion of List Elements The del statement removes an element or slice from a list by position....

    Deletion of List Elements The del statement removes an element or slice from a list by position. The list method list.remove(item) removes an element from a list by it value (deletes the first occurance of item) For example: a = ['one', 'two', 'three'] del a[1] for s in a: print(s) b = ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b'] del b[1:5] print(b) b.remove('a') print(b) # Output: ''' one three ['a', 'f', 'a', 'b'] ['f', 'a', 'b'] ''' Your textbook...

  • Given a string S that contains lowercase English letters representing different types of candies. A substring...

    Given a string S that contains lowercase English letters representing different types of candies. A substring of a string S is a string Ssub that occurs in S. For example, "twix" is a candy name which is the substring of "twtwixtwixnerdstwixnerds". Each candy costs 1 unit. You can pick some consecutive candies such that you can create a palindrome of length L by using some or all picked candies while the number of all possible cases K (all possible palindromes)...

  • COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]]...

    COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]] is the minimum    * of the set S={a[i][index[i]] for every i such that index[i]<a[i].length}    * If the set S is empty, returns -1    * Runs in time a.length.    *    * NOTE: normally this would be private, but leave it    * public so we can test it separately from your merge.    */    public static int argMin(int [][]...

  • How do i Overload the & operator to concatenate two arrays?, so elements from both arrays...

    How do i Overload the & operator to concatenate two arrays?, so elements from both arrays will be seen Below is code i have so far. everything works except the operator overload of &. The & operator only works when both array are equal, first array smaller then second, fails when first array is the largest. class smartArray{ public: int *elements; // dynamic array, memory is allocated in the constructor. Use *this to access size member. int length(); // returns...

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
Active Questions
ADVERTISEMENT