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
What is impact of Internet<br> in our lives
NeTakaya

Answer:

The Internet has changed business, education, government, healthcare, and even the ways in which we interact with our loved ones—it has become one of the key drivers of social evolution. The changes in social communication are of particular significance.

7 0
3 years ago
What is likely to happen to the economy when there’s too much money or credit circulating?
Svetlanka [38]
It depends on HOW much money is circulating. If governments just print money with nothing to back it, hyperinflation occurs. If there's a bit too much money and credit, inflation happens. Generally, 3% inflation is considered normal and a healthy amount by economists.
5 0
3 years ago
If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every pla
sergiy2304 [10]

If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every place you copy it to, the way to reference the cell? is known to be $C$2.

<h3>What is a cell reference in Excel?</h3>

A cell reference is known to be called a cell address and this is seen as a make up of a column letter and also those of  row number that tells a cell on a worksheet.

Hence, If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every place you copy it to, the way to reference the cell? is known to be $C$2.

Learn more about cell referencing from

brainly.com/question/19035038

#SPJ1

8 0
2 years ago
What are some ways you can use the Effect Options dialog box to customize animations in a presentation? Check all
aliina [53]
The first and the 3 ones
4 0
2 years ago
Read 2 more answers
Use a web browser to find three examples of static webpages and three examples of dynamic webpages, and note the URLs for each p
shepuryov [24]

Answer:

Static web pages are sent as it is at web server without being processed additionally.

Dynamic web pages content may change, and server hosting dynamic web pages return content after processing trough a program.

Examples of dynamic and static web pages are below

Explanation:

<em><u>dynamic websites</u></em>

f o o t y r o o m  (.co) It is a football website. Displays latest highlights and football stats. It is dynamic because it gives live match scores, as the scores change, content change as well.

a c c u w e a t h e r (.com) It shows weather information. It is dynamic because when requested, displays current weather information.

x e (.com)   It is a currency website. Dynamic because it shows live exchange rates.

<em><u>static websites</u></em>

s c i p y - l e c t u r e s (.org) It is a website about scientific python environment. It is static because it gives same content whenever requested.

d o g a c a n d u . b l o g s p o t (.com) it is a blog. Static because the requested content doesn't change unless the blogger adds a new story.  

z t a b l e (.net) It is a website about z-score values and includes z-tables. It is static because its displayed as it is.

5 0
3 years ago
Other questions:
  • One random part of Chess is whether the white side or the black side moves first? A. True B. False
    10·2 answers
  • Allie needs to add a long row of numbers. She should enter a
    13·2 answers
  • Write a program that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions
    13·1 answer
  • Businesses use spreadsheets to keep track of financial________.
    14·1 answer
  • What are two names for the database that holds digital signatures provided by os manufacturers, such as microsoft and red hat?
    6·1 answer
  • Which of the following is a benefit, as well as a risk, associated with peer-to-peer networks?
    6·2 answers
  • Any part of the computer that you can touch is called ________.
    6·1 answer
  • What is human data,
    8·1 answer
  • Corey set up his presentation for delivery to his team.
    8·1 answer
  • Anyone have an answer for 4.9 lesson code practice
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!