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
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains...
Using python, please do the following. 1. Write regular expressions. (a) Capture any string that contains at least three digits. (b) Capture any word that starts with one lowercase character, and either ends with two digits or with three vowels. 2. Given the following statements: string = """ Supreme executive power derives from a mandate from the masses , not from some farcical aquatic ceremony .""" words = string . split () Write a short program, using the re module,...
Write a program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
C++ Part B: (String) Program Description: Write a word search program that searches an input data...
C++ Part B: (String) Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount) ; (15%)...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int main() {    …. } Rewrite the program include the following statements. Include the header file fstream, string, and iomanip in this program. Declare inFile to be an ifstream variable and outFile to be an ofstream variable. The program will read data from the file inData.txt and write output to the file outData.txt. Include statements to open both of these files, associate inFile with...
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...
In the following C code, Which variable if NOT of primitive data type? A. a B....
In the following C code, Which variable if NOT of primitive data type? A. a B. b C. c D. d int a = 10; double b = 20.0; float c = false; char d[5] = "Hello"; // here we define a string In programming language C, the implementation of a string data type is limited dynamic length, which means the length of a string variable is fixed once it has been defined. A. True B. False In C# programming...
Write a program in C++ that inputs an unknown number of test scores (assume that there...
Write a program in C++ that inputs an unknown number of test scores (assume that there is a maximum of 150 scores). Ask the user how many scores that they will be entering. The program should have at least 3 functions. Make sure the functions perform the following: Calculate the average score Find the highest score Find the lowest score Sort the list from highest to lowest Output the number of scores, the average, the sorted list, the highest, and...
1. If we perform a regression, using data from 157 countries, with life expectancy as the...
1. If we perform a regression, using data from 157 countries, with life expectancy as the y-variable and infant mortality rate as the x-variable, we get R2 = 0.81. Which of the following is true a.Differences in infant mortality rates among countries can explain 81 percent of the variability in life expectancy. b.Because R2 is so high, we can be sure that linear regression is appropriate. c.We can accurately predict life expectancy from infant mortality in 81 percent of countries....
There are two ways to write loops: (1) iterative, like the for-loops we're used to using,...
There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print an array backwards, where 'first' is the first index // of the array, and...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT