Write a program to show users a set of choices, and then respond to those choices...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program to show users a set of choices, and then respond to those choices until they choose to quit ('q'). For each option, write a function. Each function should do as follows: halfstring() - Ask the user to enter the string of even length. Your function should display the last half string. For example, HelloWorld should display World. first three_char() - As the k user to enter the string. Your function should display the string made up of the first three characters. For example, HelloWorld will display Hel. If the string is shorter than length 3, display whatever there is, so "He" yields "He", and the string is empty, then display "Empty String." When a user enters 'q', it should display "See you later". See the sample output. 1 Welcome! What would you like to do? [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 1 Please input string of even length: HelloWorld World [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: 1 Please input string of even length: hello Please enter an even string. [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: 2 Please enter a string: test tes [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 2 Please enter a string: tes tes [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 2 Please enter a string: Empty string. [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: q See you later. Write a program to show users a set of choices, and then respond to those choices until they choose to quit ('q'). For each option, write a function. Each function should do as follows: halfstring() - Ask the user to enter the string of even length. Your function should display the last half string. For example, HelloWorld should display World. first three_char() - As the k user to enter the string. Your function should display the string made up of the first three characters. For example, HelloWorld will display Hel. If the string is shorter than length 3, display whatever there is, so "He" yields "He", and the string is empty, then display "Empty String." When a user enters 'q', it should display "See you later". See the sample output. 1 Welcome! What would you like to do? [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 1 Please input string of even length: HelloWorld World [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: 1 Please input string of even length: hello Please enter an even string. [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: 2 Please enter a string: test tes [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 2 Please enter a string: tes tes [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [9] Enter 'q' to print quit. Enter your options: 2 Please enter a string: Empty string. [1] Enter 1 to print Half string. [2] Enter 2 to print First three characters. [q] Enter 'q' to print quit. Enter your options: q See you later.
Expert Answer:
Related Book For
Computer Architecture A Quantitative Approach
ISBN: 9780128119051
6th Edition
Authors: John L. Hennessy, David A. Patterson
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Mary, Ali and Nzioka are trading as Mali enterprises. They share profits and losses in the ratio of 2 = 1 1 respectively. The following is a statement of comprehensive income for the year ended 31st...
-
Renton Custom Windows produces custom windows for business and residential customers who supply Renton with architectural specifications. At the start of 2017, three jobs were in process: Cost...
-
Construct an 80% confidence interval for the difference p M p W in the nightmare frequency data summarized in Case Study 9.4.2.
-
What measures of location are commonly computed for frequencies?
-
Mr. Fresser, age 67, owns 80% of the common shares of Fresser Ltd., a CCPC. The other 20% is owned by his daughter, Elana, who has worked in the business with Mr. Fresser for the past 22 years. When...
-
1. What are the main challenges for MNCs when they do business in African markets. Using the PESTL for your analysis. 2. What PESTEL factors should a foreign firm consider when contemplating entering...
-
7. Write a method named promptAndReadInt which will: 1. Prompt the user to enter an integer, using the text "Enter an integer:" 2. Read in an integer from the user 3. Return the integer read in 8....
-
Dick and Francis, who share profits and losses equally, decide to dissolve their partnership as at 30 June 2017. Their statement of financial position on that date was as follows: The accounts...
-
For the following regression equation: Demand \(=1.5+0.7\) Income +0.5 Need a. Specify the dependent and independent variables. b. What will be the demand when income is 0 and need is 1 ?
-
Use the data in Table 27.2 to answer this question. If Japan was experiencing a current account deficit and brought about a fall in the value of the yen, what would you expect to happen to the...
-
Stored in Countries, perform a natural logarithmic transformation on per capita GDP and develop a regression model by using per capita GDP, natural logarithm of per capita GDP, and population growth...
-
Here is the trial balance of Falta Ltd as at 30 April 2016: Given the following information as at 30 April 2016, draw up a statement of profit or loss and statement of financial position for the year...
-
The adjusted gross estate of Howard Stark, decedent, is $12 million. Included in the gross estate is all of the stock in Stark Munitions, Inc. (E & P of $1.3 million), valued at $4.6 million as...
-
When is the indirect pattern appropriate, and what are the benefits of using it?
-
Using the sample program results in Figure 2.33: a. What are the overall size and block size of the second-level cache? b. What is the miss penalty of the second-level cache? c. What is the...
-
Consider a case in which each of the eight cores on a Pixel Visual Core device is connected through a four-port switch to a 2D SRAM, forming a core+memory unit. The remaining two ports on the switch...
-
One challenge for architects is that the design created today will require several years of implementation, verification, and testing before appearing on the market. This means that the architect...
-
A balloon is launched at sea level, where the air pressure is \(100 \mathrm{kPa}\). The helium has a volume of \(1000 \mathrm{~m}^{3}\) at this altitude. What is the volume of the helium when the...
-
A balloon is at a height of \(5.0 \mathrm{~km}\) and is descending at a constant rate. The buoyancy force is directed ; the drag force is directed A. Up, up B. Up, down C. Down, up D. Down, down...
-
A balloon is launched at sea level, where the air pressure is \(100 \mathrm{kPa}\). The density in the hot-air chamber is \(1.0 \mathrm{~kg} / \mathrm{m}^{3}\). What is the density of the air when...
Study smarter with the SolutionInn App