Question

Assume that the variable data refers to the string "myprogram.exe". Write the expressions that perform the...

Assume that the variable data refers to the string "myprogram.exe". Write the expressions that perform the following tasks: a. Extract the substring "gram" from data. b. Truncate the extension ".exe" from data. c. Extract the character at the middle position from data.

Homework Answers

Answer #1

Assuming PYTHON language

To extract a substring from a given string, we put a colon(:) in the subscript and last index after : is not counted and is excluded.

a.)  print(data[5:9]) as g has index 5 and m has index 8. So we need to print from index 5 to 9 as 9 is excluded.

b.) print(data[0:9]) as first m of 'myprogram' has index 0 and last m of 'myprogram' has index 8. So we need to print from index 0 to 9 as 9 is excluded.

c.) print(data[6:7]) since middle character has index 6. So we need to print from index 6 to 7 as 7 is excluded.

Know the answer?
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
Similar Questions
1. Assume the following rules of associativity and precedence for expressions: Precedence           Highest                 *
1. Assume the following rules of associativity and precedence for expressions: Precedence           Highest                 *, /, not                               + , - , &, mod                               - (unary)                               = , / = , 6 , 6 = , 7 = , 7                               and Lowest                              or, xor Associativity         Left to right Assume the only operands are the names a,b,c,d, and e. Write a BNF description of the precedence and associativity rules defined for such expressions.
Write a C++ program to perform the following tasks     a) Declare an integer array of...
Write a C++ program to perform the following tasks     a) Declare an integer array of size 1000.     b) Initialize the array with random values between 1 and 9.     c) Write the code to find and print, how many 1’s occur in the array.
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and no other characters) and prints 1) the "least" character in the string, where one character is less than another if it occurs earlier in the alphabet (thus 'a' is less than 'C' and both are less than 'y') and 2) the index of the first occurrence of that character. When comparing letters in this problem, ignore case - i.e. 'e' and 'E' should be...
Question 4 Write a regular expression that generates each of the following language constructs: (1) String...
Question 4 Write a regular expression that generates each of the following language constructs: (1) String constants with the following specifications: A string constant consists of any sequence of characters enclosed by the quotation marks: “ and ”       The sequence may be empty.                    The sequence cannot span multiple lines.       Don’t worry about escape characters (assume that they won’t appear in the input).       (2)  Multiple-line comment in C, C++ and JAVA with the following specifications:        The comment consists of any sequence...
Write a regular expression that generates each of the following language constructs: (1) String constants with...
Write a regular expression that generates each of the following language constructs: (1) String constants with the following specifications: A string constant consists of any sequence of characters enclosed by the quotation marks: “ and ” The sequence may be empty.​ The sequence cannot span multiple lines. Don’t worry about escape characters (assume that they won’t appear in the input). (2) Multiple-line comment in C, C++ and JAVA with the following specifications: The comment consists of any sequence of characters...
This is for C++ A string is a palindrome if reverse of the string is same...
This is for C++ A string is a palindrome if reverse of the string is same as the original string. For example, “abba” is palindrome, but “abbc” is not palindrome. Basically a string with a plane of symmetry in the middle of it is considered a palindrome. For example, the following strings are palindromic: "abbbbba", "abba", "abbcbba", "a", etc. For this problem, you have an input string consisting of both lowercase or uppercase characters. You are allowed to pick and...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Perform the following problem: For the following data: (sorted) 3 4 5 8 8 10 12...
Perform the following problem: For the following data: (sorted) 3 4 5 8 8 10 12 12 20 22 1. Calculate A) average or average F. The range b) The median g) The Intercuartilico range C. Fashion h) Variance The Middle range Standard deviation The middle axis j) the Coefficient of variation 2. Draw the block diagram and Box & Wisker lines. 3. Then identify the values. 4. are data biased? Indicate which way and why?
write a statement that declares char variable named gender initialized to the character m in c++...
write a statement that declares char variable named gender initialized to the character m in c++ additionally, What is the value of number after the following code executes? int a=5; int b=10; int number = a++ + b++; lastly, The break; is required in every case block of a switch statement true or false and A default block is required in every switch statement true or false
Write UNIX commands to perform the following tasks. Each task must use exactly one line of...
Write UNIX commands to perform the following tasks. Each task must use exactly one line of command. Unless stated otherwise, all files are assumed to be at your current working directory. a) (10 points) Print your current working directory into a file named file1 b) (10 points) Assume that your current working directory is NOT the same as your home directory. Print all file and subdirectory names of your home directory into a file named file2. c) (15 points) Copy...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • XYZ is a calendar-year corporation that began business on January 1, 2017. For 2018, it reported...
    asked 15 minutes ago
  • Although aging and death are realities that all individuals have to deal with at some point...
    asked 39 minutes ago
  • Implement the following functions with AVR assembly language 1) 2-byte addition (i.e, addition on 16-bit numbers)...
    asked 48 minutes ago
  • Assume you have a chemical compound (HA) that is a weak acid which changes color upon...
    asked 1 hour ago
  • A company has two divisions. The first division consists of project management and generated $4,523,367 of...
    asked 1 hour ago
  • Practice Quiz 1 Use the following information to answer questions 1 through 5.                              &
    asked 1 hour ago
  • 3) The corrosion of iron is an electrochemical process that involves the standard reduction potentials given...
    asked 1 hour ago
  • Type or paste question here In 2015, the United States is still recovering from the recession....
    asked 1 hour ago
  • Failures of a critical machine part due to cyclical vibration has a gamma distribution with a...
    asked 2 hours ago
  • f(x)=ln(1+2x), a=4,n=3,3.7<=x<=4.3 (b) Use Taylor's Inequality to estimate the accuracy of the approximation f  Tn(x) when x...
    asked 2 hours ago
  • What is the meaning of convergent and divergent series? Explain your answer with example.
    asked 2 hours ago
  • Based on what you have learned in the textbook about feminism, discuss the approach by the...
    asked 3 hours ago