Question

In: Computer Science

preform a piece of python code that focuses on string operations, thank you.

preform a piece of python code that focuses on string operations, thank you.

Solutions

Expert Solution

rstring = "Python Language"
print(len(rstring)) #Calculates the length of the string
print(rstring.index("n")) #This will print location of first Occurence of letter n
print(rstring.count("n")) #This will print no of times letter n appeared in the string
print(rstring[7:15]) #This will print the string from 7th location till 15th location
print(rstring.upper()) #This will convert string into uppercase and print it
print(rstring.lower()) #This will convert string into lowercase and print it
print(rstring.split(" ")) #This will split the string into bunch of strings grouped together in a list

Code Screenshot:-

Output:-


Related Solutions

Write the following Python code: A string X is an anagram of string Y if X...
Write the following Python code: A string X is an anagram of string Y if X can be obtained by arranging all characters of Y in some order, without removing any characters and without adding new characters. For example, each of the strings "baba", "abab", "aabb" and "abba" is an anagram of "aabb", and strings "aaab", "aab" and "aabc" are not anagrams of "aabb". A set of strings is anagram-free if it contains no pair of strings which are anagrams...
Please do this code with python. Thank you! struct Node {     int data;     struct...
Please do this code with python. Thank you! struct Node {     int data;     struct Node* left;     struct Node* right; }; // Node creation struct Node* newNode(int data) {     struct Node* nn         = new Node;     nn->data = data;     nn->left = NULL;     nn->right = NULL;     return nn; } // Function to insert data in BST struct Node* insert(struct Node* root, int data) {   if (root == NULL)         return newNode(data);     else {...
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
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
Do the following code by using python: ( Thank!) You roll two six-sided dice, each with...
Do the following code by using python: ( Thank!) You roll two six-sided dice, each with faces containing one, two, three, four, five and six spots, respectively. When the dice come to rest, the sum of the spots on the two upward faces is calculated. • If the sum is 7 or 11 on the first roll, you win. • If the sum is 2, 3 or 12 on the first roll (called “Mygame”), you lose (i.e., the “house” wins)....
Please based on my python code. do the following steps: thank you Develop a method build_bst...
Please based on my python code. do the following steps: thank you Develop a method build_bst which takes a list of data (example: [6, 2, 4, 22, 34, 9, 6, 67, 42, 55, 70, 120, 99, 200]) and builds a binary search tree full of Node objects appropriately arranged. Test your build_bst with different sets of inputs similar to the example provided above. Show 3 different examples. Choose 1 example data.  Develop a function to remove a node from a bst...
In Python Which initial value of x will make the following piece of code leave a...
In Python Which initial value of x will make the following piece of code leave a 9 in the final value of x? x = ____? if x < 7:    x = x + 1 x = x + 2 a. 11 b. 9 c. 7 d. None of the above Which initial value of x will make the following piece of code leave a 20 in the final value of x? x = ____? if x * 2...
please use python to solve this problem. Math and String operations Write a script to perform...
please use python to solve this problem. Math and String operations Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals the remainder of...
please give complete code in python using def function thank you! Validate Credit Card Numbers Credit...
please give complete code in python using def function thank you! Validate Credit Card Numbers Credit card numbers can be quickly validated by the Luhn checksum algorithm. Start at the rightmost digit save one (the last being the checksum digit). Moving left, double the value of every second digit. If the doubled value is greater than nine, then subtract 9 from the doubled value to renormalize within the range 0–9. Sum all the digits including the checksum digit. If this...
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT