My code(python):
strng = input("Enter a sentence or phrase:\n\n")
print ("You entered:", strng)
def get_num_of_characters(strng):
countChar = 0
for i in range(0, len(strng)):
countChar = countChar + 1
return countChar;
def output_without_whitespace(strng):
strWithoutSpace = ""
for i in range(0, len(strng)):
if strng[i] != ' ':
strWithoutSpace = strWithoutSpace + strng[i]
return strWithoutSpace;
print ("\nNumber of characters:",get_num_of_characters(strng))
print ("String with no whitespace:",output_without_whitespace(strng))
(1) Prompt the user to enter a string of their choosing. Output the string.
Ex:
Enter a sentence or phrase:
The only thing we have to fear is fear itself.
You entered: The only thing we have to fear is fear itself.
(2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this function.
(3) Extend the program by calling the get_num_of_characters() function and then output the returned result.
(4) Extend the program further by implementing the output_without_whitespace() function. output_without_whitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the output_without_whitespace() function in main().
Ex:
Enter a sentence or phrase:
The only thing we have to fear is fear itself.
You entered: The only thing we have to fear is fear itself. Number of
characters: 46 String with no whitespace: Theonlythingwehavetofearisfearitself.
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images
- #include <iostream>using namespace std; char* duplicateWithoutBlanks(char *word){int len = sizeof(word); char *new_str = new char[len + 1]; int k = 0; for (int i = 0; i < len; ++i){if (word[i] != ' ')new_str[k++] = word[i];} new_str[k] = '\0'; return new_str;} int main(){// Testing code char word[] = "Hello, World!"; char* result = duplicateWithoutBlanks(word); cout<< "word: "<< word<< "\nResult: "<< result; ; return 0;} What to change to out put the same word without blank?arrow_forwardUsing the Python language answer the following questions below. Please tell me what program you use if it is IDLE or Atom or a python website please provide the website you use.arrow_forward#include<stdio.h>#include<string.h>struct info{char names[100];int age;float wage;};int main(int argc, char* argv[]) {int line_count = 0;int index, i;struct info hr[10];if (argc != 2)printf("Invalid user_input!\n");else {FILE* contents = fopen (argv[1], "r");struct info in;if (contents != NULL) {printf("File has been opened successfully.\n\n");while (fscanf(contents, "%s %d %f\n",hr[line_count].names, &hr[line_count].age, &hr[line_count].wage) != EOF) {printf("%s %d %f\n", hr[line_count].names, hr[line_count].age, hr[line_count].wage);line_count++;}printf("\nTotal number of lines in document are: %d\n\n", line_count);fclose(contents);printf("Please enter a name: ");char user_input[100];fgets(user_input, 30, stdin);user_input[strlen(user_input)-1] = '\0';index = -1;for(i = 0; i < line_count; i++){if(strcmp(hr[i].names, user_input) == 0){index = i;break;}}if(index == -1)printf("Name %s not found\n", user_input);else{while(fread(&in, sizeof(struct info), 1,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education