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
Katla is a project manager. One of the programmers on her team comes to her and says that he permanently deleted some code mista
Aleonysh [2.5K]

Answer:

Version Control - Maintains the code log history and changes overtime.

8 0
3 years ago
What does CRUD programming means and why do we need to learn it?
Slav-nsk [51]

Answer:

CRUD Meaning : CRUD is an acronym that comes from the world of computer programming and refers to the four functions that are considered necessary to implement a persistent storage application: create, read, update and delete.

Why we need to learn it? : The ability to create, read, update and delete items in a web application is crucial to most full stack projects. CRUD is too important to be ignored, so learning it first can really improve confidence within unfamiliar stacks.

6 0
3 years ago
What kind of keybord is tis ned help pleese I don't no wat itis​
Murrr4er [49]

Answer:

judging by the logo at the top it's a hyperx keyboard and looks to be the alloy core rgb... hope this helps!

8 0
3 years ago
Read 2 more answers
Pls answer thank you​
Sav [38]

Answer:

That would be your opinion

5 0
2 years ago
In cell C15, enter a formula using an IF function to determine if you need a loan. Your available cash is located on the Data sh
san4es73 [151]

The IF function allows the user to make logical comparison among values.

The formula to enter in cell 15 is:  

\mathbf{=IF(\$A\$4 > \$A\$3, "yes", "no")}

In Excel, the syntax of an IF function is:

\mathbf{ = IF ( logical_test , [value_if_true] , [value_if_false] ) }

The representation in the above formula is as follows:

  • logical_test  <em>are the values to be compared</em>
  • [value_if_true] <em>is the return value if the condition is true</em>
  • [value_if_false] <em>is the return value if the condition is false</em>

The cells to compare are given as:  Cell A3 and Cell A4

Where cell A4 contains the car price

So, the IF function is:

\mathbf{=IF(A4 > A3, "yes", "no")}

First, the formula checks if the value of A4 is exceeds A3.

  • If true, the function returns "yes"
  • Else, it returns "no"

To make use of the absolute cell referencing., we simply include the dollar sign between the cell names

Hence, the required formula is:

\mathbf{=IF(\$A\$4 > \$A\$3, "yes", "no")}

Read more about IF functions at:

brainly.com/question/16026173

7 0
3 years ago
Other questions:
  • For film editors, which task comes last in their workflow pattern?
    12·2 answers
  • An example of what you can post that shows kindness to other
    15·1 answer
  • Consider the following declaration: double[] sales = new double[50]; int j; Which of the following correctly initializes all the
    11·1 answer
  • Janet has to create a web page for a software company that should be accessible from both desktop computers and mobile devices.
    9·2 answers
  • The filter feature in excel allows you to look at what Data?
    7·1 answer
  • "Bullet Lists" can be which of the following?
    12·2 answers
  • Implement a recursive program that takes in a number and finds the square of that number through addition. For example if the nu
    5·1 answer
  • ____________ is a script or a tool that obtains privileges of a root
    8·1 answer
  • Match each with the correct answer.
    7·1 answer
  • a network administrator for a large oil company has discovered that a host on the company network has been compromised by an att
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!