Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8.2, Problem 8CP
Program Plan Intro
String slicing:
- • A span of items that are taken from a sequence denotes a slice.
- • Span of characters are obtained when a string is sliced.
- • The slices of strings are termed as substrings.
Syntax:
The syntax for string slicing is shown below:
string[start : end]
Explanation:
In the above syntax,
- • The “start” denotes index of the first character in slice.
- • The “end” denotes index of the end of slice.
- • The expression would return a string that contains a copy of characters from “start” till “end”.
- • If the “end” value is not provided, then it will consider till the end of string.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the purpose of this code$Error=[] ;
int* p:
int a[3]{1, 2, 3};
p = a;
What is the value of *(p+2)?
#ifndef lab5ExF_h
#define lab5ExF_h
typedef struct point
{
char label[10];
double x ; // x coordinate for point in a Cartesian coordinate system
double y; // y coordinate for point in a Cartesian coordinate system
double z; // z coordinate for point in a Cartesian coordinate system
}Point;
void reverse (Point *a, int n);
/* REQUIRES: Elements a[0] ... a[n-2], a[n-1] exists.
* PROMISES: places the existing Point objects in array a, in reverse order.
* The new a[0] value is the old a[n-1] value, the new a[1] is the
* old a[n-2], etc.
*/
int search(const Point* struct_array, const char* target, int n);
/* REQUIRES: Elements struct-array[0] ... struct_array[n-2], struct_array[n-1]
* exists. target points to string to be searched for.
* PROMISES: returns the index of the element in the array that contains an
* instance of point with a matching label. Otherwise, if there is
* no point in the array that its label matches the target-label,
* it should return -1.
* If there are more than…
Chapter 8 Solutions
Starting Out with Python (4th Edition)
Ch. 8.1 - Assume the variable name references a string....Ch. 8.1 - What is the index of the first character in a...Ch. 8.1 - If a string has 10 characters, what is the index...Ch. 8.1 - Prob. 4CPCh. 8.1 - Prob. 5CPCh. 8.1 - Prob. 6CPCh. 8.2 - Prob. 7CPCh. 8.2 - Prob. 8CPCh. 8.2 - Prob. 9CPCh. 8.2 - What will the following code display? mystring =...
Ch. 8.3 - Prob. 11CPCh. 8.3 - Prob. 12CPCh. 8.3 - Write an if statement that displays Digit" if the...Ch. 8.3 - What is the output of the following code? ch = 'a'...Ch. 8.3 - Write a loop that asks the user Do you want to...Ch. 8.3 - Prob. 16CPCh. 8.3 - Write a loop that counts the number of uppercase...Ch. 8.3 - Assume the following statement appears in a...Ch. 8.3 - Assume the following statement appears in a...Ch. 8 - This is the first index in a string. a. 1 b. 1 c....Ch. 8 - This is the last index in a string. a. 1 b. 99 c....Ch. 8 - This will happen if you try to use an index that...Ch. 8 - This function returns the length of a string. a....Ch. 8 - This string method returns a copy of the string...Ch. 8 - This string method returns the lowest index in the...Ch. 8 - This operator determines whether one string is...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns true if a string...Ch. 8 - This string method returns a copy of the string...Ch. 8 - Once a string is created, it cannot be changed.Ch. 8 - You can use the for loop to iterate over the...Ch. 8 - The isupper method converts a string to all...Ch. 8 - The repetition operator () works with strings as...Ch. 8 - Prob. 5TFCh. 8 - What does the following code display? mystr =...Ch. 8 - What does the following code display? mystr =...Ch. 8 - What will the following code display? mystring =...Ch. 8 - Prob. 4SACh. 8 - What does the following code display? name = 'joe'...Ch. 8 - Assume choice references a string. The following...Ch. 8 - Write a loop that counts the number of space...Ch. 8 - Write a loop that counts the number of digits that...Ch. 8 - Write a loop that counts the number of lowercase...Ch. 8 - Write a function that accepts a string as an...Ch. 8 - Prob. 6AWCh. 8 - Write a function that accepts a string as an...Ch. 8 - Assume mystrinc references a string. Write a...Ch. 8 - Assume mystring references a string. Write a...Ch. 8 - Look at the following statement: mystring =...Ch. 8 - Initials Write a program that gets a string...Ch. 8 - Sum of Digits in a String Write a program that...Ch. 8 - Date Printer Write a program that reads a string...Ch. 8 - Prob. 4PECh. 8 - Alphabetic Telephone Number Translator Many...Ch. 8 - Average Number of Words If you have downloaded the...Ch. 8 - If you have downloaded the source code you will...Ch. 8 - Sentence Capitalizer Write a program with a...Ch. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Word Separator Write a program that accepts as...Ch. 8 - Pig Latin Write a program that accepts a sentence...Ch. 8 - PowerBall Lottery To play the PowerBall lottery,...Ch. 8 - Gas Prices In the student sample program files for...
Knowledge Booster
Similar questions
- Computer Science C++ Write a program that: Gets a character array (C-string) using cin.get to allow blanks in the C-string Prints the C-string (what they input) Prints the length (number of characters) in the C-stringarrow_forwardWrite code so that you take three integers a,b, and c display a^b - c.arrow_forwardWhat will the following code output? int *MyPtr, MyNums[ ]= {-1, 0, 3, 4}: MyPtr = MyNums; cout<< MyPtr <arrow_forwardq3/write program in c++ language read 2D array and print the elements that are not divisible 7 _le aaudll Jaid *arrow_forward#include <stdio.h>#include <stdint.h> char sz_1[] = "Upper/LOWER.";char sz_2[] = "mIXeD CaSe.."; /* copies psz_2 to psz_1, downcases all letters */void dostr (char* psz_1,char* psz_2) {uint8_t u8_c; while (*psz_2 != 0) {u8_c = *psz_2;if (u8_c > 0x2F) {/* make sure it is not a special char */*psz_1 = u8_c | 0x20; /* sets this bit */} else {/* leave special chars alone */*psz_1 = u8_c;}psz_1++;psz_2++;} } int main(void) {// Bug: MPLAB X v1.80 printf bug means strings vis %s don't print correctly.// So, break printf into two statements.printf("Before...\n");printf("sz_1: '"); printf(sz_1); printf("'\n");printf("sz_2: '"); printf(sz_2); printf("'\n");dostr(sz_1,sz_2);printf("After...\n");printf("sz_1: '"); printf(sz_1); printf("'\n");printf("sz_2: '"); printf(sz_2); printf("'\n");return 0;}convert it in assemblyarrow_forwardC++ Lexicographical Sorting Given a file of unsorted words with mixed case: read the entries in the file and sort those words lexicographically. The program should then prompt the user for an index, and display the word at that index. Since you must store the entire list in an array, you will need to know the length. The "List of 1000 Mixed Case Words" contains 1000 words. You are guaranteed that the words in the array are unique, so you don't have to worry about the order of, say, "bat" and "Bat." For example, if the array contains ten words and the contents are cat Rat bat Mat SAT Vat Hat pat TAT eat after sorting, the word at index 6 is Rat You are encouraged to use this data to test your program.arrow_forward#include <stdio.h>#include <stdlib.h> typedef struct Number_struct { int num;} Number; void Swap(Number* numPtr1, Number* numPtr2) { /* Your code goes here */} int main(void) { Number* num1 = NULL; Number* num2 = NULL; num1 = (Number*)malloc(sizeof(Number)); num2 = (Number*)malloc(sizeof(Number)); int int1; int int2; scanf("%d", &int1); scanf("%d", &int2); Thank you so much but i forgot to put this how i would fit in into this. num1->num = int1; num2->num = int2; Swap(num1, num2); printf("num1 = %d, num2 = %d\n", num1->num, num2->num); return 0;}arrow_forward#include <iostream>#include<iomanip>using namespace std; int main(){ const int ROW_HOURS=6; //declare variables const int CL_PAYRATE=2; double total_payout=0; double hours[ROW_HOURS][CL_PAYRATE]={ //declare array {0,12.85}, {0,12.85}, {0,12.85}, {0,11.75}, {0,11.75}, {0,11.15} }; cout<<fixed; cout<<setprecision(2); //setprecision of double values upto 2 decimal point for(int i=0;i<6;i++) //using loop get input from user { cout<<"Enter the hours worked by employee "<<i+1<<": "; cin>>hours[i][0]; //store values into hours } for(int i=0;i<6;i++) { double payout=hours[i][0]*hours[i][1]; //calculate payout of emplyee total_payout=total_payout+payout;…arrow_forward* The value of [1/2 *[5/2] ] is 1 2 3 0.5arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning