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
when I was playing Mobile legends bang bang online Match The game logged Me out and when I was Trying To reconnect it failed and
Helen [10]

Answer:

it's most prolly a bug.The game crashes a lot tbh

5 0
3 years ago
Which type of electronic payment is typically favored in b2b?
Dennis_Churaev [7]
Electronic checks would<span> typically be favored in b2b</span>
4 0
2 years ago
The internet has provided great opportunities for fundraising. true/false
alekssr [168]
True, sites such as kickstarter and just giving are fantastic examples of such.
8 0
2 years ago
How does job growth in digital media compare to job growth in print-based media companies?
tatuchka [14]

Answer:

A. Job growth in digital media has been powerful, while print-based media companies are cutting jobs at record levels.

Explanation:

Digital media is both inexpensive and instant. Based on the art and design, it might be less expensive than print media. Campaigns and content can be created, produced, and maintained far more quickly than printed media. Digital media is dynamic and may create user data. Digital media has had a significant influence on how we obtain our daily news. As it is more easy to read, most individuals choose to acquire their news via phone applications. With the increased usage of digital media as a news source, it is worth considering if print media will become outdated.

Print media has been established for decades, and it evolved as a dominant source of news. In the last decade, an increasing number of print media businesses have expanded out from regular print and begun providing news on digital services. Young millennials, in instance, appear to invest additional time online than reading printed publications.

8 0
1 year ago
You need to protect sensitive files from unauthorized users even if the disk is stolen. What feature should you use and on what
Lynna [10]

Answer:

EFS on NTFS

Explanation:

EFS (Encryption File System) allows users to store confidential information about a computer when people who have physical access to your computer could otherwise compromise that information, intentionally or unintentionally. EFS is especially useful for securing sensitive data on portable computers or on computers shared by several users.  An attacker can also steal a computer, remove the hard drive(s), place the drive(s) in another system, and gain access to the stored files. Files encrypted by EFS, however, appear as unintelligible characters when the attacker does not have the decryption key.

The Encrypting File System (EFS) that is included with the operating systems provides the core file encryption technology to store NTFS files encrypted on disk.

7 0
3 years ago
Other questions:
  • If you need to show slides on a wide-screen monitor, you might change their size to: Select one: a. Onscreen Show (16:9) b. Onsc
    11·1 answer
  • Orifice tubes are A. coded in American models only. B. coded by number for easy identification. C. similarly but not exactly siz
    12·1 answer
  • What does it mean when system ui has stopped?
    9·1 answer
  • Write a program that reads in a temperature value in °F. Create a function ConvertFahrenheit that takes that value as a paramete
    7·1 answer
  • Many businesses use robotic solutions. Which department of the food and beverage industry uses robotic solutions on a large scal
    10·2 answers
  • Write a full class definition for a class named Counter, and containing the following members:________
    9·1 answer
  • Hvhblfffffffff<br> eafafaefafsa
    9·2 answers
  • Gabby is creating a game in which users must create shapes before the clock runs out. Which Python module should Gabby use to cr
    15·2 answers
  • Help me please. I dont really understand this.
    12·2 answers
  • Which arcade game, released in 1972, is considered to be the first to be commercially successful?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!