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...
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...
I'm working on python code which is substring matching. For example, the given string is input...
I'm working on python code which is substring matching. For example, the given string is input "CTTGTGATCTCGTGTCGTGGGTAG", and a substring we want to find in the main one is "GTGG". So the code will print out the position and the substrings in the main which has exactly one different position. For example, start at position 4 the substring is GTGA since there is only one letter different, and so on. Even though we know that string index starts at 0,...
Please provide Python code that does the following: 3) Write a program that takes a string...
Please provide Python code that does the following: 3) Write a program that takes a string as input, checks to see if it is comprised entirely of letters, and if all those letters are lower case. The output should be one of three possible messages: Your string is comprised entirely of lower case letters. Your string is comprised entirely of letters but some or all are upper case. Your string is not comprised entirely of letters. Your program may NOT:...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std;...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std; float series(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum += r[i];    return sum; } float parallel(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum = sum + (1 / r[i]);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT