1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
muminat
3 years ago
15

Create the strAnalysis() function that takes 1 string argument and returns a string message. The message will be an analysis of

a test string that is passed as an argument to strAnalysis(). The function should respond with messages such as:
"big number"
"small number"
"all alphabetic"
"multiple character types"
The program will call str_analysis() with a string argument from input collected within a while loop. The while loop will test if the input is empty (an empty string "") and continue to loop and gather input until the user submits at least 1 character (input cannot be empty).
The program then calls the str_analysis() function and prints the return message.
Sample input and output:

enter nothing (twice) then enter a word
enter word or integer:
enter word or integer:
enter word or integer: Hello
"Hello" is all alphabetical characters!

alphabetical word input:
enter word or integer: carbonization
"carbonization" is all alphabetical characters!

numeric inputs:
enter word or integer: 30
30 is a smaller number than expected

enter word or integer: 1024
1024 is a pretty big number
loop until non-empty input is submitted

Once the user gives input with characters use the input in calling the str_analysis() function.

Additional Details:
In the body of the str_analysis() function:

Check if string is digits
if digits: convert to int and check if greater than 99
if greater than 99 print a message about a "big number"
if not greater than 99 print message about "small number"
check if string isalpha then (since not digits)
if isalpha print message about being all alpha
if not isalpha print a message about being neither all alpha nor all digit
call the function with a string from user input

Run and test your code before submitting
# [ ] create, call and test the str_analysis() function
Computers and Technology
1 answer:
nydimaria [60]3 years ago
7 0

Answer:

def str_analysis(s):

   if s.isdigit():

       s = int(s)

       if s > 99:

           message = str(s) + " is a pretty big number"

       else:

           message = str(s) + " is a smaller number than expected"

       

   elif s.isalpha():

       message = s + " is all alphabetical characters!"

   else:

           message = "There are multiple character types"

   

   return message;

   

s = input("enter word or integer: ")

while s != "":

   print(str_analysis(s))

   s = input("enter word or integer: ")

Explanation:

- Check if the string is digit, alphabetical, or mixed inside the function

- Ask the user for the input

- Call and print the result of the <em>str_analysis</em> function inside the while loop

- Keep asking for the input until the given string is empty

You might be interested in
Write a new program called Lab7D that will read strings from a text file and turn them into "encrypted code". Create a bool func
Aliun [14]

Answer:

I am writing a C program for the first part and Python program for the second part of the question.    

<h2>1st program:</h2>

#include <stdio.h>  //to use input output functions

#include <stdlib.h>  // used here to access exit function

void main() {  //start of the main() function body

char fname[100], character;

// fname is the name of the input file which contains characters and character //variable is used to store characters

FILE *original, *temporary;  

/* two pointers of File type: original is used for the original input file and temporary is used for a temporary file name aux.txt */

printf("Enter the name of the text file to encrypt : ");

//prompts the user to enter the name of the file to be encrypted

scanf("%s",fname); //reads the name of the file from user

original=fopen(fname, "r"); //open the input file in read mode

if(original==NULL)  {

//displays the following message if the file is empty or does not exists

 printf("Cannot open original file");  

 exit(1);  }  //program exits

temporary=fopen("aux.txt", "w");

//creates a temporary file named aux.txt and open that file in write mode

if(temporary==NULL)  { //if temporary file could not be created

 printf("Cannot create a temporary file");

 fclose(original); //closes the original input file

 exit(2);  }  //program exits

while(1)  {

 character=fgetc(original);  

/*pointer original moves through the input file and gets input from original input file one character at a time and store it in character variable */

 if(character==EOF)  

//when all characters are obtained and pointer is at end of file  {

  break;  //the loop breaks }

 else   {  //if EOF is not yet reached

  character=character+100;  

//add 100 to each character to encrypt the characters

  fputc(character, temporary);

 // fputc() writes a single character at a time to aux file } }

fclose(original);  //closes input file

fclose(temporary); //closes aux file

original=fopen(fname, "w");  //opens input file in write mode

if(original==NULL) { //if file does not exist display following message

 printf("Cannot open the original file to write");

 exit(3);  } //program exits

temporary=fopen("aux.txt", "r"); //open aux.txt file in read mode

if(temporary==NULL)  { //if pointer temporary is NULL

 printf(" Cannot open temporary file to read");

 fclose(original);  //closes input file

 exit(4);  } //program exits

while(1)  {

 character=fgetc(temporary);

//obtains every character from aux file pointed by temporary

 if(character==EOF)  //if end of file is reaced {

  break;   } //the loop breaks

 else   { //if end of file is not reached

  fputc(character, original);  

//puts every character to input file }  }

printf(" %s is encrypted \n", fname);  

//displays this message when input file is successfully encrypted

//closes input and aux text files

fclose(original);

fclose(temporary); }  

Explanation:

The program first asks the user to enter the name of the file. Then the program uses two pointers original for input file and temporary for aux text file. It first opens the file whose name is entered by the user and reads that file by getting each single character using fgetc() until the pointer reaches the end of the file. While reading each character of the input file, it encrypts every character using and puts that encrypted content in temporary file names aux.txt using fputc() until the pointer reaches the end of the file. Lastly all the encrypted strings of the are placed in the original input text file.

<h2>Second program:</h2>

# bool function that accepts character as parameter and returns true if its a #vowel and false otherwise

def isVowel(character):  

   if character.lower() in 'aeiou':  #converts uppercase char to lowercase

       return True  #return true if character is a vowel    

   else:

       return False #returns false if input character is not a vowel

The program has a function isVowel() which takes a character as a parameter to check if that character is a vowel. If character is in uppercase  letters, it handles these characters using lower() method to convert the character to lowercase and then returns true if that character is a vowel otherwise returns false. To check the working of the function you can replace True and False with print statement such as:

if character.lower() in 'aeiou':

       print("It is a vowel")

   else:

       print("It is not a vowel")

And after that you can call this function and pass a character to it as:

isVowel('i')

5 0
3 years ago
What is the correct name for the words Home, Insert, Design, Layout, References, etc. in the ribbon in Word 2016?
KIM [24]

Answer:

Option (B) i.e.,Tabs is the correct option.

Explanation:

Because the followings are the tabs in the ribbon of Ms Word 2016, with the help of the tabs we can edit, update, modify, design, change or insert layout and also we can insert themes, etc in our document. These tabs are important to create our document attractive and provide good designs in the document. We also create business cards, invitation card and other important things with the help of tabs.

7 0
2 years ago
Read 2 more answers
कम्प्यूटर में एक समस्या को ठीक करने के लिए एक कार्यक्रम या कोनफीगरेशन परिवर्तन के बाद किए जाते हैं
VARVARA [1.3K]

restart.is done after the computer is passed through configuration

3 0
3 years ago
You discover memory is corrupted, what would be an indication of a software vs. a hardware issue?
bearhunter [10]
Hey there!

Memory (RAM) is considered to be hardware since it is a physical component that makes up the computer and is accessed through the CPU rather than internal code that makes the computer run (which is software). Therefore, if you are having issues with the memory, it is likely a problem with a memory chip, making it a hardware issue. 

Hope this helped you out! :-)
8 0
3 years ago
What is a gamer?
mixer [17]

Answer:

It is <em>definitely </em>D.

Explanation:

I am a gamer myself so this question is easy for me. It's slim to none to be wrong when you view my answer!!!

7 0
2 years ago
Other questions:
  • Mark works as a Network Administrator for NetTech Inc. The company has a Windows Server 2008 domain-based network. The network c
    7·1 answer
  • True or false? Colons are required when entering the MAC address into the Reservation window?
    14·1 answer
  • Jonathan works with a team of graphic designers. They have a collection of images and have divided the image editing work among
    5·2 answers
  • Five examples of technology in community​
    7·2 answers
  • The ______________ shows that you have fully researched the topic and gives you a chance to prove your claim.
    8·1 answer
  • Write a program that prompts the user to enter their name store this value in a variable called name Prompt the user for their c
    10·1 answer
  • how risk can impact each of the seven domains of a typical IT infrastructure: User, Workstation, Local Area Network (LAN), Local
    7·1 answer
  • Which statement best describes what happens when a computer starts?
    9·1 answer
  • Explain different users of computer in briefly?​
    14·1 answer
  • Information to develop a project network is collected from the.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!