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
Andreas93 [3]
3 years ago
9

def getCharacterForward(char, key): """ Given a character char, and an integer key, the function shifts char forward `key` steps

. Return the new character. If `char` is not a single character, return `None`. If `key` is not an integer, return -1. """ return "stub"
Computers and Technology
1 answer:
zhenek [66]3 years ago
8 0

Answer:

  1. def getCharacterForward(char, key):  
  2.    charList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  3.    if(len(char) > 1):
  4.        return None  
  5.    elif(not isinstance(key, int)):
  6.        return -1
  7.    else:
  8.        index = charList.find(char)
  9.        if(index + key <= 25):
  10.            return charList[index + key]
  11.        else:
  12.            return charList[(index + key)% 26]
  13. print(getCharacterForward("C", 4))
  14. print(getCharacterForward("X", 4))

Explanation:

Firstly, define a charList that includes all uppercase alphabets (Line 2). We presume this program will only handle uppercase characters.

Follow the question requirement and define necessary input validation such as checking if the char is a single character (Line 4). We can do the validation by checking if the length of the char is more than 1, if so, this is not a single character and should return None (Line 5). Next, validate the key by using isinstance function to see if this is an integer. If this is not an integer return -1 (Line 6 - 7).

Otherwise, the program will proceed to find the index of char in the charList using find method (Line 9). Next, we can add the key to index and use the result value to get forwarded character from the charList and return it as output (Line 11).

However, we need to deal a situation that the char is found at close end of the charList and the forward key steps will be out of range of alphabet list. For example the char is X and the key is 4, the four steps forward will result in out of range error. To handle this situation, we can move the last two forward steps from the starting point of the charList. So X move forward 4 will become B. We can implement this logic by having index + key modulus by 26 (Line 13).  

We can test the function will passing two sample set of arguments (Line 15 - 16) and we shall get the output as follows:

G

B

You might be interested in
Match each of the following terms to its function:_________
Crazy boy [7]

Answer:

I = B

II = E

III = A

IV = D

V = C

7 0
3 years ago
The results of the SPEC CPU2006 bzip2 benchmark running on an AMD Barcelona has an instruction count of 2.389E12, an execution t
xxTIMURxx [149]

Answer:

inside a butt whole

Explanation:

3 0
3 years ago
Meg wants to preview all images in a folder so that she can quickly find the image she wants. Which view will help her do this?
Liono4ka [1.6K]
Thumbnails is the answer

3 0
3 years ago
What is one outcome of an integration point?
mylen [45]

Answer:

What is one outcome of an integration point? It provides information to a system builder to potentially pivot the course of action. It bring several Kanban processes to conclusion. It supports SAFe budgeting milestones.

5 0
4 years ago
A condensing oil furnace operates at a higher efficiency because part of the heat output is:________
mario62 [17]

Because some of the heat produced by a condensing oil furnace is latent heat, it functions more efficiently.

<h3>Is the capacity of an oil furnace expressed in input or output?</h3>

The steady-state heat output of the furnace, expressed in BTU/h, is known as the heating (bonnet) capacity of oil heating appliances. Today's typical oil-fired central heating units for residential use have heating capacity ranging from 56,000 to 150,000 BTU/h.

<h3>What unit of heat is the capacity of an oil furnace stated in?</h3>

The amount of heat (Btu per gallon) released during the combustion process, in which the oxygen from the air combines with the hydrogen and carbon in the fuel, is how a fuel oil's heat of combustion value is expressed.

To learn more about condensing oil furnace and heating (bonnet) capacity, Visit:

<u>brainly.com/question/14783076</u>

#SPJ4

4 0
2 years ago
Other questions:
  • How to you put a color into a cell? <br> a.Shading<br><br> b.Fill<br><br> c.Color<br><br> d.Insert
    8·1 answer
  • A malware-infected networked host under the remote control of a hacker is commonly referred to as:
    10·2 answers
  • Drivers should scan 10-12 secound down the road looking of potential hazards
    5·1 answer
  • Using the Sakila database, create a query that displays the film title, description, as well the actor first and last name for a
    12·1 answer
  • The CUSTOMERS and SALES tables contain these columns:
    6·1 answer
  • What type of Microsoft Server serves as an email server?
    7·2 answers
  • Select the correct answer.
    13·1 answer
  • The blue section of the following Venn diagram could represent which of the following Boolean statements?
    14·1 answer
  • You receive an email that appears to legitimately be from your Bank. The email indicates the need for verification of your infor
    15·2 answers
  • Create a Python program that asks the user in which direction to go? north, South East, or West?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!