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
In a mobile phone network, how many times as strong would
steposvetlana [31]

Answer:

how many times as strong would what?

put your question in the replies to this answer and I'll gladly answer it

Explanation:

May I have brainliest please? :)

6 0
2 years ago
Pa sagot po TLE-10<br>need den po Ng solution thank you​
horsena [70]

Answer:

HAHHAHAHA HAAHA g abbabanjaja abunjing <em><u>abunjin</u></em><em><u>✌</u></em><em><u>✌</u></em><em><u>✌</u></em><em><u>✌</u></em><em><u>✌</u></em><em><u>✌</u></em>

3 0
2 years ago
Which solution eliminates the need for dedicated high-speed WAN connections between sites
s344n2d4d5 [400]

Answer:

running in the 90 s intensifies

Explanation:

4 0
2 years ago
Por favor definir que es un pseudocódigo y que es un diagrama de flujo.
marusya05 [52]

Answer:

que

Explanation:

8 0
3 years ago
Read 2 more answers
For python how do I ask the user how many numbers they want to enter and then at the ending add those numbers up together?
Digiron [165]

I am not too familiar with the Python language, but the algorithm would be something like this:

1. create a variable for the sums of the number

2. read in how many numbers the user wants to enter (let's call it N)

and then create a for loop:

for N times

read in the next number

increase the sum variable by that number

Hopefully this helps!

8 0
3 years ago
Other questions:
  • In the software development life cycle, what is the role of participants in the planning phase? The participants’ role in the pl
    6·1 answer
  • How can i become an ailen?
    5·2 answers
  • A student is curious about how a Web site appears on his computer screen. On a piece of paper,
    9·1 answer
  • After a suspected identity fraud case has been resolved, you should:
    10·2 answers
  • I have been charged for brainly plus yet I still have to watch ads why? What do I do?
    12·2 answers
  • In Java:
    15·1 answer
  • Which tab automatically becomes available after inserting a text box? Drawing Tools Insert Text Box Tools Shape Tools
    15·2 answers
  • I need some help with this assignment. I'm having difficulty trying come up ideas to use here. Can I get any help?
    5·1 answer
  • Es costoso construir un robot
    6·1 answer
  • Accenture has put together a coalition of several ecosystem partners to implement the principles of blockchain and Multi-party S
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!