Write a function which takes as parameter a character string x composed of a combination of four words: 'bed', 'lamp', 'desk', 'phone'. The function must calculate the percentage of each word. The function must print (print) these four percentages of letters words rounded to two decimal places. To make this display, multiply each percentage by 100 and round this to 2 decimal places. • Then it is necessary to display (print) a single message indicating the median. A grade (word) is median if at least 1/2 (half) of the students obtained that grade or better. So, If at least 1/2 (half) of the letters are bed ': display Median is bed. If not, then if at least 1/2 of the letters are bed ', lamp': display Median is lamp 2. If not, then if at least 1/2 of the letters are bed, lamp, desk: print "The median is desk", otherwise print "The median is phone".

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Write a function which takes as parameter a character string x
composed of a combination of four words: 'bed', 'lamp', 'desk',
'phone'.
The function must calculate the percentage of each word.
The function must print (print) these four percentages of letters
words rounded to two decimal places. To make this display,
multiply each percentage by 100 and round this to 2 decimal
places.
• Then it is necessary to display (print) a single message
indicating the median. A grade (word) is median if at least 1/2
(half) of the students obtained that grade or better. So, If at least
1/2 (half) of the letters are bed ': display Median is bed. If not, then
if at least 1/2 of the letters are bed ', lamp': display Median is lamp
2. If not, then if at least 1/2 of the letters are bed, lamp, desk: print
"The median is desk", otherwise print "The median is phone".
Transcribed Image Text:Write a function which takes as parameter a character string x composed of a combination of four words: 'bed', 'lamp', 'desk', 'phone'. The function must calculate the percentage of each word. The function must print (print) these four percentages of letters words rounded to two decimal places. To make this display, multiply each percentage by 100 and round this to 2 decimal places. • Then it is necessary to display (print) a single message indicating the median. A grade (word) is median if at least 1/2 (half) of the students obtained that grade or better. So, If at least 1/2 (half) of the letters are bed ': display Median is bed. If not, then if at least 1/2 of the letters are bed ', lamp': display Median is lamp 2. If not, then if at least 1/2 of the letters are bed, lamp, desk: print "The median is desk", otherwise print "The median is phone".
Expert Solution
Step 1

Since no programming language is mentioned, I am using python.

Algorithm:

  1. Start
  2. Implement a method check() which takes a string as argument 
  3. Inside the method, convert string s to lower case
  4. Calculate bed=s.count("bed")
  5. Calculate lamp=s.count("lamp")
  6. Calculate desk=s.count("desk")
  7. Calculate phone=s.count("phone")
  8. Print percentage of each word 
  9. Print round((bed*100/total),2)
  10. Print round((lamp*100/total),2)
  11. Print round((desk*100/total),2)
  12. Print round((phone*100/total),2)
  13. If bed>=total/2, print median is bed
  14. Else If bed+lamp>=total/2, print median is lamp
  15. Else if bed+lamp+desk>=total/2, print median is desk 
  16. Else print median is phone
  17. Inside the main method, call check method by passing a string composed of combinations of given four words
  18. Stop
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY