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
lys-0071 [83]
3 years ago
11

Implement function easyCrypto() that takes as input a string and prints its encryption

Computers and Technology
1 answer:
jasenka [17]3 years ago
4 0

Answer:

The program written in python is as follows;

import string

def easyCrypto(inputstring):

      for i in range(len(inputstring)):

             try:

                    ind = string.ascii_lowercase.index(inputstring[i])

                    pos = ind+1

                    if pos%2 == 0:

                           print(string.ascii_lowercase[ind-1],end="")

                    else:

                           print(string.ascii_lowercase[ind+1],end="")

             except:

                    ind = string.ascii_uppercase.index(inputstring[i])

                    pos = ind+1

                    if pos%2 == 0:

                           print(string.ascii_uppercase[ind-1],end="")

                    else:

                           print(string.ascii_uppercase[ind+1],end="")

anystring = input("Enter a string: ")

easyCrypto(anystring)

Explanation:

The first line imports the string module into the program

import string

The functipn easyCrypto() starts here

def easyCrypto(inputstring):

This line iterates through each character in the input string

      for i in range(len(inputstring)):

The try except handles the error in the program

             try:

This line gets the index of the current character (lower case)

                    ind = string.ascii_lowercase.index(inputstring[i])

This line adds 1 to the index

                    pos = ind+1

This line checks if the character is at even position

                    if pos%2 == 0:

If yes, it returns the alphabet before it

                           print(string.ascii_lowercase[ind-1],end="")

                    else:

It returns the alphabet after it, if otherwise

                           print(string.ascii_lowercase[ind+1],end="")

The except block does the same thing as the try block, but it handles uppercase letters

<em>              except: </em>

<em>                     ind = string.ascii_uppercase.index(inputstring[i]) </em>

<em>                     pos = ind+1 </em>

<em>                     if pos%2 == 0: </em>

<em>                            print(string.ascii_uppercase[ind-1],end="") </em>

<em>                     else: </em>

<em>                            print(string.ascii_uppercase[ind+1],end="") </em>

<em />

The main starts here

This line prompts user for input

anystring = input("Enter a string: ")

This line calls the easyCrypto() function

easyCrypto(anystring)

You might be interested in
To save a document with a new name, click _______ in the navigation bar and enter a new filename.
cricket20 [7]
Click the save as button
3 0
3 years ago
When was the GoPro camera invented?​
masya89 [10]

Answer:

2002

Explanation:

Please mark me brainliest :)

6 0
3 years ago
Carlos, an algebra teacher, is creating a series of PowerPoint presentations to use during class lectures. After writing, format
yarga [219]

Answer:

see explanation

Explanation:

Carlos can make a copy of the old presentation that preserves all the formatting, and replace old content with new information.

5 0
3 years ago
What did early computers use to store each bit?
Damm [24]

Answer:

A vacuum tube

4 0
3 years ago
Read 2 more answers
Vocational schools are also called all of the following except:
Salsk061 [2.6K]
A vocational school can also be called all of the following except a certification school.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Olivia wants to add buttons and clickable features to her website. Which language should she use?
    10·2 answers
  • Who is the owner of microsoft company​
    12·1 answer
  • What is the most recent version of Microsoft Windows?
    12·2 answers
  • Which method is used for resolving data dependency conflict by the compiler itself?
    6·1 answer
  • Given that add, a function that expects two integer parameters and returns their sum, and given that two variables, euro_sales a
    7·1 answer
  • As a general rule, the number of bullet points on a slide should not exceed _____. a.2 b.4 c.8 d.10
    9·1 answer
  • What are potential problems with using nanorobots ?
    14·1 answer
  • All states that have altered judicial selection techniques in recent years have adopted some form of:
    10·2 answers
  • How to beat level 50 in give up robot 2
    5·1 answer
  • Which of the following is NOT a possible combination of values of the variables in this program when it finishes running?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!