Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8, Problem 3SA
What will the following code display?
mystring = 'abcdefg'
print(mystring[2:5])
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
What is the purpose of this code$Error=[] ;
Write code so that you take three integers a,b, and c display a^b - c.
#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 assembly
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- #include<stdio.h>#include<stdlib.h>#include<string.h>/* function that converts the change into count of 50,20,10,5 and stores the count in changeArray*/int coinChange(int changeArray[10][4],int index,int change){int count50=0,count20=0,count10=0,count5=0;while(change > 0){if(change > 0 && change <=95 && change% 5 == 0){if(change >= 50){change -= 50;count50++;}else if(change >= 20){change -= 20;count20++;}else if(change>=10){change -= 10;count10++;}else if(change>=5){change -= 5;count5++;}}}changeArray[index][0]=count50;changeArray[index][1]=count20;changeArray[index][2]=count10;changeArray[index][3]=count5;return change;}/* function that reads 'coins.txt' and stores names in names array, coin values in coins array, compute change and stores change count in change array */int readFromFile(char names[10][100],int coins[],int change[10][4]){int index=-1,i=0;FILE *fp;fp=fopen("coins.txt","r");if(fp==NULL){printf("File doesnot…arrow_forward#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…arrow_forwardComputer 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_forward
- vi. What is wrong with following code: T *p = new T[10];delete p;arrow_forward#include <stdio.h>#include <string.h>#define SIZE 6struct Student{char name[50];int id;float mark;};int Search1(char input[], struct Student data[]);int Search2(int input, struct Student data[]);int main() {char search_name[30];int search_id;int result1, result2;struct Student list[SIZE] = {{"Amylia", 544199, 75.4},{"Cheong", 143566, 92.3},{"Harry", 109774, 65.5},{"Krishnan", 334514, 86.7},{"Melissa", 257890, 55.4},{"Timothy",144656, 77.8}};printf("Enter Student Name: ");gets(search_name);result1 = Search1(search_name, list);//Answer for part (a)(ii) – Display the matching index of result1printf("Enter Student ID: ");scanf("%d",&search_id);result2 = Search2(search_id,list);//Answer for part (a)(iii)- Display the matching index of result2return 0;}//Answer for part (a)(i) – function definition for Search1//Answer for part (a)(iii) – function definition for Search2arrow_forward// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forward
- // MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…arrow_forward// MichiganCities.cpp - This program prints a message for invalid cities in Michigan. // Input: Interactive // Output: Error message or nothing #include <iostream> #include <string> using namespace std; int main() { // Declare variables string inCity; // name of city to look up in array const int NUM_CITIES = 10; // Initialized array of cities string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}; bool foundIt = false; // Flag variable int x; // Loop control variable // Get user input cout << "Enter name of city: "; cin >> inCity; // Write your loop here // Write your test statement here to see if there is // a match. Set the flag to true if city is found. // Test to see if city was not found to determine if // "Not a city in Michigan" message should be printed.…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
- char[] b = {'a', 'b', 'c', '5'}; System.out.println(b.charAt(2)); displays an error occurs because b is not a variable of type String the character c the character barrow_forwardWrite EBNF formarrow_forwardThe elements displayed by the following section code For(m=1;m<=5;m++) cout <<a[m] <<"" ;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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 LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher: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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Dictionaries - Introduction to Data Structures (Episode 8); Author: NullPointer Exception;https://www.youtube.com/watch?v=j0cPnbtp1_w;License: Standard YouTube License, CC-BY