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
Python short one to three line answers 45 a. Write a conditional that multiplies the value...
Python short one to three line answers 45 a. Write a conditional that multiplies the value assigned to pay by one-and-a-half if worked_overtime contains the value True. b. Assume that c is a variable that has been given a string value. Write an expression whose value is True if and only if c is NOT what is called a whitespace character(space,tab, or newline) c. Assume that c is a variable that has been given a string value. Write an expression...
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