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
Which option represents the location of the Goal Seek function?
sweet-ann [11.9K]

Answer:b

Explanation:

3 0
3 years ago
Read 2 more answers
Bran is writing a book on operation system errors. Help him complete the sentences.
MrMuchimi

Answer:

The answer to this question is given below in the explanation section.

Explanation:

A  <u>          </u><u>logic   </u><u>         </u>error occurs when a program runs accurately, but yields the wrong result. Therefore, it is difficult to detect. However, a program can detect <u>       </u><u>syntax  </u><u>                  </u>errors rapidly, because they occur in the structure of programming code during the compilation stage.

8 0
3 years ago
What is the BCC feature used for?
exis [7]

Answer:

to send an email to someone without revealing that person’s email address to others on the distribution list

Explanation:

BAM

7 0
3 years ago
Read 2 more answers
The expectations I would discuss with Erica regarding the usage of the internet
ryzh [129]

Answer:

Tell her about cyber bullies

Tell her about hackers

stalkers

identity theft

spam

Sorry if wrong

Explanation:

8 0
3 years ago
Assume that an int variable counter has already been declared. Assume further a variable counterPointer of type "pointer to int"
Triss [41]

Answer:

Following are the statement:

counterPointer = &counter;

Explanation:

The following statement is correct because in the question it is given that there is an integer data type variable i.e., "counter" and there is another integer data type pointer variable i.e., "counterPointer" and finally we write a statement in which the pointer variable points to the integer variable.

5 0
3 years ago
Other questions:
  • Desktop, laptop, and tablet computers, and mobile devices are classified as _______.
    7·1 answer
  • What kind of problems could you run into if you format a cell with the wrong format for the data type?
    15·2 answers
  • In the structure of a conventional processor, what is the purpose of the data path?
    15·1 answer
  • IOS jail broken or Android unrooted which is better to hack with
    6·1 answer
  • What are some characteristics of filtering junk email in Outlook 2016? Check all that apply.
    10·2 answers
  • Which option should you select to accept a tracked change? A. Accept B. Reject C. Review D. Delete
    8·2 answers
  • "If a user on a laptop complains that they are unable to sign into Windows even though they are certain they are entering the co
    12·1 answer
  • How many total bits are required for a direct mapped cache with 16 KB of data and 4 word blocks Assuming a 32 bit address
    12·1 answer
  • tell us things u did as a kid but don't want to admit to it (best gets brainly 5 stasr and a thank you)
    13·2 answers
  • Why is it easier to spot a syntax error than a logical error?​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!