Question

In: Computer Science

7.15 Translate the following string method invocations to functions calls in namespace str: (Python) (a) '...

7.15 Translate the following string method invocations to functions calls in namespace str:

(Python)

(a) ' error'. upper( )

(b) ' 2, 3, 4, 5'. split(',' )

(c) ' mississippi'.count('i' )

(d) ' bell'.replace('e' , 'a' )

(e) ' '. format(1, 2, 3)

Solutions

Expert Solution

Here is the code explained as comments for you:

' error'. upper( )   #The string error will be converted to upper case, and that string
                   #will then be converted to upper case. So, it will be ' ERROR'
' 2, 3, 4, 5'. split(',' ) #The string will be separated/split based on commas.
                   #So, the list is now: [' 2', ' 3', ' 4', ' 5']
'mississippi'.count('i') #The number of 'i's in the string will be counted.
                   #So, will return 4.              
' bell'.replace('e' , 'a' )   #The character e is replaced with the character a in the string bell.
                   #So, the result is ball
' '.format(1, 2, 3)   #Will just leave a space.


Related Solutions

#include <iostream> using namespace std; string* callMe(string*& s){ static string* str = new string{"Chiqita Banana"}; str...
#include <iostream> using namespace std; string* callMe(string*& s){ static string* str = new string{"Chiqita Banana"}; str = s; return str; } int main() { string* s = new string{"Hey Google"}; string* str = callMe(s);    cout << "Call me \'" + *str +"\'"; return 0; } 1. What is the output or the error of this program? Call me 'Hey Google' 2. And please explain the data flow in detail (to memory level)? Please help question 2 with explanation, thank...
USE JAVA PLEASE Use recursion to implement a method public static int indexOf(String text, String str)...
USE JAVA PLEASE Use recursion to implement a method public static int indexOf(String text, String str) that returns the starting position of the first substring of the text that matches str. Return –1 if str is not a substring of the text. For example, s.indexOf("Mississippi", "sip") returns 6. Hint: You must keep track of how far the match is from the beginning of the text. Make that value a parameter variable of a helper method.
For these of string functions, write the code for it in C++ or Python (without using...
For these of string functions, write the code for it in C++ or Python (without using any of thatlanguage's built-in functions) You may assume there is a function to convert Small string into the language string type and a function to convert your language's string type back to Small string type. 1. int [] searchA,ll(string in...str, string sub): returns an array of positions of sub in in...str or an one element array with -1 if sub doesn't exist in in...str
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace std; char ch; int main() {    cin >> ch;    cout << "You inputted " << ch << endl;    ch++;    cout << "Next character is " << ch << endl; if (ch <= ‘Z’)         cout << “Could be luppercase\n”;    return 0; }
Programming language is Java. Consider you have already created a validateString(String str) method that validates a...
Programming language is Java. Consider you have already created a validateString(String str) method that validates a String to ensure it contains exactly 4 characters. Create code that calls this method, sending user input as an argument (actual parameter). The user should be continuously prompted to enter a different string and informed of an error if the method returns false.
Write an example of a Python while loop that is infinite, calls the functions first(), second()...
Write an example of a Python while loop that is infinite, calls the functions first(), second() and third() in that order in the body of the loop, but skips calling second() and third() if first() returns a value of False, and exits if second() returns a value of False. Declare a Python function named sumEm() that accepts three numeric parameters and returns the sum of the three numbers. Assume sumEm() is declared in a module named myMod.py, which your program...
Use this code to answer the following questions:           Object obj;           String str;           Song...
Use this code to answer the following questions:           Object obj;           String str;           Song sng = new Song("Rockstar", 5);           obj = sng;              // #7           sng = str;              // #8           str = (String) obj;     // #9           sng = obj;              // #10 1a)  Write the start of the class declaration for a node in a linked list (give the name of the class and the instance variables). The name of the node should be SpecialNode. The data in each SpecialNode will...
Using Python math functions that produce x,y values. The results of these function calls will be...
Using Python math functions that produce x,y values. The results of these function calls will be used as input to another program of your choice for plotting the results. Plots can be completed using Excel any other online or other graphing tool you have available. Use standard I/O The Math functions and values range of x-values are described below: a. Generate x, sin(x) for x values ranging from -2PI -> 2PI with an increment of PI/64 b. Generate x, cos(x)...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0) return 0; else if (n <= 2) return 1; else { temp = fib(n – 1); return temp + fib(n-2); } } int main() { int num; cout << "Which fibonacci number? "; cin >> num; cout << fib(num) << endl; return 0; } You must use equates to access the stack and follow the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT