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
frozen [14]
2 years ago
12

Your task is to build a palindrome from an input string.A palindrome is a word that readsthe same backward or forward. Your code

will take the first 5 characters of the user input, and create a 9-character palindrome from it.Words shorter than 5 characters will result in a runtime error when you run your code. This is acceptablefor this exercise, however you already know how to validate user input with an IF statement.Some examplesof input words and the resulting palindromes:
Computers and Technology
1 answer:
White raven [17]2 years ago
7 0

Answer:

The program in Python is as follows:

word = input("Word: ")

if len(word) < 5:

   print("At least 5 characters")

else:

   pal = word[0:5]

   word = word[0:4]

   word = word[::-1]

   pal+=word

   print(pal)

Explanation:

This gets the word from the user

word = input("Word: ")

This checks if the length of the word is less than 5.

if len(word) < 5:

If yes, this tells the user that at least 5 characters is needed

   print("At least 5 characters")

If otherwise

else:

This extracts the first 5 characters of the word into variable named pal

   pal = word[0:5]

This extracts the first 5 characters of the word into variable named word

   word = word[0:4]

This reverses variable word

   word = word[::-1]

This concatenates pal and word

   pal+=word

This prints the generated palindrome

   print(pal)

You might be interested in
Write short notes on the following:<br>I. keyboard ii.Control unit iii.printer​
Andreas93 [3]

Answer:

- the Keyboard:

The keyboard is a handheld device used to input alphabet, numbers, symbols and characters to a monitor. It also houses the special manipulative and function keys.

- the Control Unit:

The control unit is a component of the CPU which directs the operation of the processor.

- the Printer:

The printer is an external hardware output device which takes electronic data stored on a device and creates a hard copy.

4 0
2 years ago
Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, latinamericasales2009.txt, define four ofstr
Lynna [10]

Answer:

ofstream asia("asiasales2009.txt");  //It is used to open asiasales2009.txt files with the asia objects.

ofstream europe("europesales2009.txt");  //It is used to open  europesales2009.txt files with the europe objects.

ofstream africa("africasales2009.txt"); //It is used to open africasales2009.txt files with the africa objects.

ofstream latin("latinamericasales2009.txt");//It is used to open latinamericasales2009.txt files with the latin objects.

Explanation:

  • The above code is written in the c++ language which is used to open the specified files with the specified objects by the help of ofstream class as described in the question-statements.
  • The ofstream is used to open the file in the c++ programing language, so when a user wants to use the ofstream to open the file in written mode, then he needs to follow the below syntax--

              ofstream object("file_name_with_extension");

4 0
3 years ago
Write a method named square that accepts an integer argument and returns the square of that argument.
BaLLatris [955]

Answer:

The method is as follows:

double square(int num){

return num*num;

}

Explanation:

Written in C++

This first line defines the method

double square(int num){

This line returns the square of num

return num*num;

}

<em>I've added the full program as an attachment where I include the main method</em>

Download cpp
7 0
3 years ago
The byte that
qwelly [4]
The decimal value 15 would be A. 00001111
4 0
1 year ago
Write an expression that continues to bid until the user enters 'n'.
Sergio [31]

I've seen this problem before, you just need the solution to the 'while' loop, right?


Assuming your variable names are the same as the generic question your while loop should look like this:


while (keepGoing != 'n')

7 0
3 years ago
Other questions:
  • The google android mobile operating system is a proprietary system, for use on only approved devices.​
    10·1 answer
  • What kind of voltage do solar cells generate? Solar cells produce ______ voltage which is not usable by most household appliance
    15·1 answer
  • Create a simple main() that solves the subset sum problem for any vector of ints. Here is an example of the set-up and output. Y
    12·1 answer
  • Which is not an example of a mobile operating system?
    9·1 answer
  • An interpreter _______. converts the procedural language one statement at a time converts the source code into machine language
    12·1 answer
  • When Hallmark designs its website so that a teenage girl can send a theme card to her boyfriend's cell phone, what is the primar
    6·1 answer
  • Each professional association has
    7·1 answer
  • What are the consequences of plagiarism?
    7·2 answers
  • PLEASE HELP ME ASAP!!! Looking at the misty rain and fog (pictured above) Explain at least two defensive driving techniques you
    15·1 answer
  • SmartArt is a Microsoft Office tool for creating what?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!