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
To add text to a slide when using presentation software, you need to add a text box. To add a text box, click the Text Box butto
Amiraneli [1.4K]

The answer is the second choice, "Insert."


On Microsoft Powerpoint, when you click on the insert tab you can find the text box button.

3 0
3 years ago
Read 2 more answers
Explain why the effect of stimulant and depressants do not necessarily counteract<br>each other​
zzz [600]

Answer:

Adderall is a stimulant and alcohol is a depressant. This does not mean that the two substances cancel each other out. Instead, they compete with each other in your body. This effect can cause serious problems.

5 0
3 years ago
It is possible to collaborate on a presentation with a group of people using the Internet.
DerKrebs [107]

Answer:

True

Explanation:

4 0
4 years ago
What is the function of this logical comparator! =?
rewona [7]

Answer:

See explanation

Explanation:

!= means not equal

The given operator is not a logical operator but rather a comparison operator.

It compares two expressions, values or variables and returns true if the items being compared are not equal.

3 0
3 years ago
Which type of password would be considered secure
max2010maxim [7]
Try using at least one capital letter and multiple number and symbols
Example: [email protected]#3
5 0
4 years ago
Read 2 more answers
Other questions:
  • Which modem settings should be configured on DSL or cable modems?
    14·1 answer
  • Translate each of these statements into logical expressions using predicates, quantifiers, and logical connectives. a) Something
    7·1 answer
  • Which of the following is an acrostic RAM association mnemonic device or Please Excuse My Dear Aunt Sally.
    9·2 answers
  • Nina wants to create a digital backup of her holiday videos to view later. What two of these devices could she use?
    11·2 answers
  • Match the parts of a CPU to their fuctions
    8·1 answer
  • Varied amount of input data Statistics are often calculated with varying amounts of input data. Write a program that takes any n
    8·1 answer
  • javascript Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment
    7·1 answer
  • A __________ search engine focuses on a specific subject.<br><br>answer : Specialized
    8·1 answer
  • In MS Word we can merga cells true or false​
    13·2 answers
  • an existing technology that would allow users to transfer images from the camera to the computer without connecting them
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!