Write a "Python" function to encode a string as follows: "a" becomes "z" and vice versa, "b" becomes "y" and vice versa, etc. and "A" becomes "Z" and vice versa, "B" becomes "Y" and vice versa, etc. The function should preserve any non-alphabetic characters, that is, do not encode them but just return them as is. The function should take an unencoded string as an argument and return the encoded version. If the function is called "encrypt" then here are some sample calls to it: print(encrypt("AABBAA")) # "ZZYYZZ" print(encrypt("aabbaa")) # "zzyyzz" print(encrypt("lmno")) # "onml" print(encrypt("zzYYZZ")) # "aaBBAA" print(encrypt(encrypt("AAbbZZ"))) "AAbbZZ" print(encrypt("I have 3 dogs.") "R szev 3 wlth."T

Answers

Answer 1

This function should be able to handle all the given test cases and any other unencoded string as well. To write a Python function that encodes a string as per the given criteria, we can follow these steps:

1. Define the function and take an unencoded string as an argument.
2. Create two dictionaries - one for lowercase and one for uppercase letters - with keys as alphabets and values as their corresponding encoded letters.
3. Iterate over each character in the string and check if it is an alphabet or not. If it is, check if it is uppercase or lowercase and replace it with its corresponding encoded letter from the dictionary.
4. If it is not an alphabet, simply add it to the encoded string as is.
5. Finally, return the encoded string.
Here's the code:
def encrypt(string):
   lowercase_dict = {'a': 'z', 'b': 'y', 'c': 'x', 'd': 'w', 'e': 'v', 'f': 'u', 'g': 't', 'h': 's', 'i': 'r', 'j': 'q', 'k': 'p', 'l': 'o', 'm': 'n', 'n': 'm', 'o': 'l', 'p': 'k', 'q': 'j', 'r': 'i', 's': 'h', 't': 'g', 'u': 'f', 'v': 'e', 'w': 'd', 'x': 'c', 'y': 'b', 'z': 'a'}
   uppercase_dict = {'A': 'Z', 'B': 'Y', 'C': 'X', 'D': 'W', 'E': 'V', 'F': 'U', 'G': 'T', 'H': 'S', 'I': 'R', 'J': 'Q', 'K': 'P', 'L': 'O', 'M': 'N', 'N': 'M', 'O': 'L', 'P': 'K', 'Q': 'J', 'R': 'I', 'S': 'H', 'T': 'G', 'U': 'F', 'V': 'E', 'W': 'D', 'X': 'C', 'Y': 'B', 'Z': 'A'}
   encoded_string = ""
   for char in string:
       if char.isalpha():
           if char.islower():
               encoded_string += lowercase_dict[char]
           else:
               encoded_string += uppercase_dict[char]
       else:
           encoded_string += char
   return encoded_string
This function should be able to handle all the given test cases and any other unencoded string as well.

To know more about Python visit:

https://brainly.com/question/31722044

#SPJ11


Related Questions

Explain in not less than 3 Sentences

1. Decimal Number System


2.Binary Number System​

Answers

Answer:

The Decimal Numeral system :-

It is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral system.

Binary Number system :-

It is a number expressed in the base-2 numeral system , which uses only two symbols: typically "0" and "1". The base-2 numeral system is a positional notation with a radix of 2. Each digit is referred to as a bit, or binary digit.

hope it helps you...

If someone said to you, “Pseudocode is a waste of time! It’s just more work because you end up writing the same program twice,” how would you explain the benefits of pseudocode?

Answers

Answer:

It allows the designer to focus on main logic without being distracted by programming languages syntax.

* Since it is language independent, it can be translated to any computer language code.

* It allows designer to express logic in plain natural language.

* It is easier to write actual code using pseudocode.

* Unlike algorithms, pseudocodes are concise so pseudocodes are more readable and easier to modify.

Explanation:

6. A presentation is widely used to present and effectively​

Answers

Answer:

A Presentation is a collection of slides arranged in a systematic order. 2) A presentation ...

Explanation:

Please give thanks to all my answers and please mark as brilliant and please follow me

What line of code would you edit if you wanted a bigger sprite?This is computer science.Pick branliest if right


A.3

B.4

C.5

D.You have to edit the picture itself

Answers

pretty sure the answer is a-3

Answer:

C. 5

Explanation:

Line 3 refers to the positioning of the sprite.

Line 4 refers to the animation preset of the sprite.

Line 5 is the correct choice because in the code it references scale and a value which can be modified to make the sprite bigger. For example, from 0.3 to 0.5

If I'm right please give brainliest, thanks

WHAT IS MULTIMEDIA SUPPOSED TO MEAN ???

Answers

Answer:

using more than one medium of expression or communication

Answer:

It basically means using more than one expression or form of communication

Explanation:

What is the name of the function below?

function go(){
alert("hello everybody");
}

Answers

Answer:

It’s Java script I think and it makes something say hello everybody

Explanation:

Find the cost of 2m 20cm at 25p per metre​

Answers

Answer: 55 meters.

Explanation:

First convert the 20 cm to meters so the entire number is in meters.

1 meter = 100 cm

20 in cm is:

= 20/100

= 0.2 meters.

2.2 meters.

One meter costs 25p so 2.2 meters will cost:

= 2.2 * 25

= 55 meters

PLS HELP ASAP suppose you want to find pages that contain the word German but not the word shepherd. which search would achieve this?
German OR shepherd
German- shepherd
"GERMAN shepherd"
"German"+"shepherd"

Answers

Answer: German- shepherd

Explanation:

If I want to find pages that contain the word German but not the word shepherd, the search would achieve this would be German- shepherd.

It should be noted that other options such as German OR shepherd, "GERMAN shepherd" and "German"+"shepherd" all mean that pages containing the words German and also shepherd will be found.

The (-) sign simply means that not. Therefore, the correct option is German - shepherd which means German but not shepherd.

Answer:

German- shepherd

Explanation:

Describe some common types of charts.​

Answers

Bar chart.
Pie chart.
Line chart.

Answer:

The four most common are probably line graphs, bar graphs and histograms, pie charts, and Cartesian graphs. They are generally used for, and are best for, quite different things.

Explanation:

Line chart- A graph with points connected by lines to show how something changes in value: • as time goes by, • or as something else changes.

Example: how you are improving at a quiz each day.

Bar chart- A graph drawn using rectangular bars to show how large each value is. The bars can be horizontal or vertical. It is a really good way to show relative sizes. We can use bar graphs to show the relative sizes of many things, such as what type of car people have, how many customers a shop has on different days and so on.

Histogram- a graphical display of data using bars of different heights. It is similar to a Bar Chart, but a histogram groups numbers into ranges . The height of each bar shows how many fall into each range.

Pie chart- a special chart that uses "pie slices" to show relative sizes of data. It is a really good way to show relative sizes.

Cartesian chart- This is a type of chart that uses coordinates to pinpoint where something is on a map or graph. Using Cartesian Coordinates we mark a point on a graph by how far along and how far up it is.

A type of topology in which all the systems a connected a main cable ​

Answers

Answer:

Bus topology uses one main cable to which all nodes are directly connected. The main cable acts as a backbone for the network. One of the computers in the network typically acts as the computer server. The first advantage of bus topology is that it is easy to connect a computer or peripheral device.

A loan of $12000 was borrowed from the bank at 14% per annum calculate the interest on the loan at the end of the first year ?​

Answers

Answer:

lmasjsjsjssjjssjjssjsjjsksakkalaaooaa

Loan borrowed = $12,000

Percentage of interest on the loan per annum = 14%

We know that :

[tex]\color{hotpink}\tt \: Simple \: interest = \color{plum}\frac{principal \times rate \times time}{100} [/tex]

In this case :

principal = $12000rate = 14%time = 1 year

Simple interest at the end of the first year :

[tex] = \tt \frac{12000 \times 14 \times 1}{100} [/tex]

[tex] = \tt \frac{168000}{100} [/tex]

[tex]\color{plum}\tt = \$1680[/tex]

Thus, interest = $1680

Therefore, total interest on the loan at the end of one year = $1680

Could someone please help?​

Answers

Answer:

it looks difficult

Explanation:

you can devotingly solve it

Which item would not generate a desktop alert by default in Outlook 2016?

new contact created
meeting request received
email received
task assignment received
i couldn't find this awnser and my teacher is extending our test period for another 20 minutes. please help

Answers

Answer:

New contact created does not generate a desktop alert by default.

Explanation:

edg.2021

Answer:

A

Explanation:

1. Visual design and font/background are both essential and considered vital for the success of a web. If you are the developer, which of the two will you be focused on?

Answers

Answer:

As a developer, I'd be focused on the two starting with the front end.

Explanation:

A front-end developer simply is a user-end or client-side developer. A front-end person in web design is responsible for how a website looks and feels like, essentially, the websites' users first impression.

This is a huge task and can be very daunting even for the best developers. Whilst the back-end or the engine of a website is critical and indispensable, it is important for a developer to master the principles of front-end development first as that gives him a better perspective as to how they can better create and configure a matching or suitable back end.

Most if not all are designed to achieve a particular purpose e.g.

Increase salescommunicate informationtrainingelicit information etc

The ease with which the user is able to interact with the website will determine the extent to which the purpose of the website is achieved.

Some of the qualities of a great user interface the front end developer must keep in mind are:

Clarity Conciseness Familiarity  EfficiencyConsistency Attractiveness

Back-end has to do with the part of the website called the server.

In addition to the server, there are two other critical components of the back-end of the website:

Application and Database.

Together, these three contribute to ensuring that you have a functional website. The server, application and database, all control what happens on the front end and results in what the user will see via the browser.

There are many high-functioning websites today that have very poor interfaces.  A poor interface is a guarantee that people will spend less time on the website.

Conclusively, both ends are indispensable, as with most things, however, one should seek to understand how the user thinks and feels in relation to how they like to use a website before doing into the back-end to make that possible.

Cheers

There are different kinds of designs. As a developer, my Visual design would focus more on background.

Visual design is known to be a kind of design that strike equality between unity and variety. The use of design elements to work on the background and when done properly, gives users a nice experience.

Visual design is one that act to improve the design's or the product's aesthetic feeling.

Learn more about Visual design from

https://brainly.com/question/1332211

a collection of logically related instructions is called _______​

Answers

Answer:

Data Base from what I know

Explanation:

Which option is the default when creating appointments and meetings in a user’s own calendar as it relates to Free/Busy information that others will see when looking at the user’s calendar?

a. Free
b. Working Elsewhere
c. Busy
d. Tentative
I only have 10 minutes left so please help fast!

Answers

Answer:

C !

Explanation:

Answer:

Busy

Explanation:

What storyboarding technique uses a combination of two techniques, and which techniques does it combine?
O A. hierarchical; wheel and linear
O B. linear; webbed and hierarchical
O C. webbed; linear and hierarchical
© D. wheel; webbed and linear

Answers

Answer:

d

Explanation:

Answer:

They're right, it's c:  webbed; linear and hierarchical

Explanation:

Edmentum, I got it right.

Why is computer literacy is important.

Answers

Cause it’s a important  skill process and they want there employees to have basic skill on pc or computers. They come depending on computers and it’s most likely to be more successful on education with the use of computers

What's wrong with these codes in code HS Karel challenges(7.1.2. Racing Karel) Codes: //Below is the program that have Karel move around the race track 8 times, and end in his starting location. Everytime Karel hits a corner, he will put a ball down. At the end there should be 8 balls on each corner. function start(){ for(var i = 0; i < 5; i++){ ballSet(); wallRun(); turnLeft(); } function wallRun(){ while(frontIsClear()){ move(); } } function ballSet(){ putBall(); } }

Answers

Answer:

The program only runs 5 five since the for loop statement is limited to loop only five times.

Explanation:

In programming, a for-loop statement is used to repeat a collection of events a definite number of times. The number of loops is specified and compared with a variable to execute a block of code.

The for-loop statement in the code above declares and initializes a variable "i" to zero, runs the block of code, and increments by one if it is less than 5.

To make it run eight times, the value five should be changed to 8 instead.

Answer: you have to change the 5 to 8 since its telling you to do it 8 times

Explanation: for(var i = 0; i < 5; i++) should be for(var i = 0; i < 8; i++)

Can you all help me with this?

Answers

Answer:

(1)mobile smart phone.

(2)server computer.

(3)desktop computer

(4)laptop computer

(5)all in one computer

What was the biggest challenge you faced in getting to where you are today and how did you overcome it? Peer counseling

Answers

The biggest challenge I still am faced with today is loosing weight, it can be different for everyone but that is mine. I overcomed it by eating a lot better and not so much junk food.

create html code showing heading tags​

Answers

Answer:

Assuming you mean the HTML5 head tag, then this may work for you:

<!DOCTYPE HTML>

<html lang="en">

<head>

<title>My Very Awesome Website</title>

<link href="./css/main.css" rel="stylesheet"  />

<meta name="viewport" content="width=device-width, initial-scale=1" />

</head>

<body>

<h1>Hey look</h1>

<p>This is my awesome website!</p>

<h3>Note</h3>

<p>This website is supposed to be 100% awesome!</p>

</body>

</html>

Choose all items that are true about the two example of HTML shown on the right.

Example 1 will display differently than example 2 in a web browser.

They are styled differently, but will look the same in a web browser.

Example 2 is easier to analyze and repair.

The styling in example 2 is required by modern web browsers.

Answers

Answer:

2

Explanation:

Answer:

B and C

Explanation:

3 uses for a GPS system other than for a satellite navigation system

Answers

Answer:

Location – determining a position. Navigation getting from one location to another. Tracking – monitoring object or a personal movement. Mapping – creating maps of the world.

PLEASE HELP ITS TIMED Ishmael would like to capture a selected portion of his screen and then capture actions he performs on that selected portion. What should he do?


Use the Video from My PC command.

Use the Insert Screen Recording control.

Create a poster frame.

Use an embed code.

Answers

Answer:

Option B

Hope this Helps!!! :)

When you click on what will happen?

The font will change back to the default setting.
The document will change back to the last time you saved it.
The last step will be undone.
The last step will be redone.

Answers

The last step is undone. The default font choices in Microsoft Word are one of the biggest sources of ongoing annoyance for legal users.

What is Default setting?

you can alter just two Styles (+Body and +Headings) permanently to give your papers a more professional typography.

There is a drop-down menu labeled Fonts over to the far right. You can view a list of preconfigured font sets by clicking on Fonts. You want to select Customize Fonts from here.

You can see the Body font and the Heading font on the left. Here is where you control the two Styles, +Body and +Headings, that I mentioned previously.

Therefore, The last step is undone.

To learn more about default font, refer to the link:

https://brainly.com/question/21104940

#SPJ1

Answer: C The last step will be undone. this is the Undo Icon

Explanation:

# input a mark in a subject of a student and
Check if the student is pass or not pass [pass mark=30]​

Answers

Answer:

mark = int(input("Enter mark: "))

if (mark >= 30):

 print("Pass")

else:

 print("Not pass")

What percentage of teens say they have witnessed cyberbullying?

50

95

70

35

Answers

A Majority of Teens Have Experienced Some Form of Cyberbullying. 59% of U.S. teens have been bullied or harassed online, and a similar share says it's a major problem for people their age

254 × (×) igual 20×()682883993

Para que se utilizan las siguientes plataformas: Matlab, Labview, VisualBasic, Mplab, Micropic, PicCompiller

Answers

Answer:

MATLAB (abreviatura de MATrix LABoratory, «laboratorio de matrices») es un sistema de cómputo numérico que ofrece un entorno de desarrollo integrado (IDE) con un lenguaje de programación propio (lenguaje M). Está disponible para las plataformas Unix, Windows, macOS y GNU/Linux.

Entre sus prestaciones básicas se hallan la manipulación de matrices, la representación de datos y funciones, la implementación de algoritmos, la creación de interfaces de usuario (GUI) y la comunicación con programas en otros lenguajes y con otros dispositivos hardware.

LABVIEW (acrónimo de Laboratory Virtual Instrument Engineering Workbench) es una plataforma y entorno de desarrollo para diseñar sistemas, con un lenguaje de programación visual gráfico pensado para sistemas hardware y software de pruebas, control y diseño, simulado o real y embebido.

Visual Basic (VB) es un lenguaje de programación dirigido por eventos, desarrollado por Alan Cooper para Microsoft. Este lenguaje de programación es un dialecto de BASIC, con importantes agregados. Su primera versión fue presentada en 1991, con la intención de simplificar la programación utilizando un ambiente de desarrollo.

MPLAB es un editor IDE gratuito, destinado a productos de la marca Microchip. Este editor es modular, permite seleccionar los distintos microcontroladores soportados, además de permitir la grabación de estos circuitos integrados directamente al programador.

MICROPICUn PIC es un circuito integrado programable (Programmable Integrated Circuited), el cual contiene todos los componentes para poder realizar y controlar una tarea, por lo que se denomina como un microcontrolador. Los PIC son una familia de microcontroladores tipo RISC fabricados por Microchip Technology Inc. y derivados del PIC1650, originalmente desarrollado por la división de microelectrónica de General Instrument.

PICCOMPILER

El Portable C Compiler o Compilador de C Portable (también conocido como pcc o, algunas veces, como pccm - máquina de compilador de C portable) fue uno de los primeros compiladores para el lenguaje de programación C escrito por Stephen C. Johnson de los Laboratorios Bell a mediados de los 70, basado, en parte, en las ideas de un trabajo previo de Alan Snyder en 1973.

Explanation:

MATLAB (abreviatura de MATrix LABoratory, «laboratorio de matrices») es un sistema de cómputo numérico que ofrece un entorno de desarrollo integrado (IDE) con un lenguaje de programación propio (lenguaje M). Está disponible para las plataformas Unix, Windows, macOS y GNU/Linux.

Entre sus prestaciones básicas se hallan la manipulación de matrices, la representación de datos y funciones, la implementación de algoritmos, la creación de interfaces de usuario (GUI) y la comunicación con programas en otros lenguajes y con otros dispositivos hardware.

LABVIEW (acrónimo de Laboratory Virtual Instrument Engineering Workbench) es una plataforma y entorno de desarrollo para diseñar sistemas, con un lenguaje de programación visual gráfico pensado para sistemas hardware y software de pruebas, control y diseño, simulado o real y embebido.

Visual Basic (VB) es un lenguaje de programación dirigido por eventos, desarrollado por Alan Cooper para Microsoft. Este lenguaje de programación es un dialecto de BASIC, con importantes agregados. Su primera versión fue presentada en 1991, con la intención de simplificar la programación utilizando un ambiente de desarrollo.

MPLAB es un editor IDE gratuito, destinado a productos de la marca Microchip. Este editor es modular, permite seleccionar los distintos microcontroladores soportados, además de permitir la grabación de estos circuitos integrados directamente al programador.

MICROPICUn PIC es un circuito integrado programable (Programmable Integrated Circuited), el cual contiene todos los componentes para poder realizar y controlar una tarea, por lo que se denomina como un microcontrolador. Los PIC son una familia de microcontroladores tipo RISC fabricados por Microchip Technology Inc. y derivados del PIC1650, originalmente desarrollado por la división de microelectrónica de General Instrument.

PICCOMPILER

El Portable C Compiler o Compilador de C Portable (también conocido como pcc o, algunas veces, como pccm - máquina de compilador de C portable) fue uno de los primeros compiladores para el lenguaje de programación C escrito por Stephen C. Johnson de los Laboratorios Bell a mediados de los 70, basado, en parte, en las ideas de un trabajo previo de Alan Snyder en 1973.

___________ is a computer programming language.

Answers

Python!!! I hope that helped!!
Pascal, c+, c++ etc
Other Questions
which graph correctly represents the inequality x - 3y 6F. none of them 10 is 70% of what number? If necessary, round to the nearest tenth. The women liberation monement began Mark scored 138 points in 6 games. How many points did he score per game? what two potential outcomes did the committee see in Russia's near future? 20 POINTS!!!!!!!!!!!!!1. After the American Revolution, each state had to draw up state constitutions. Explain what liberties and principles Virginia, Pennsylvania, and the other states provided as models for state constitutions. OIGAN ME AYUDAN CON ESTO AUQUE SEA PLIS I need help I've wasted all my points trying to get an answer please don't put anything that is not helpful. In The White Umbrella, we explored a theme that envying and longing for what others have will bring you trouble and shame in the long run. How does the main character struggle with envy and longing throughout the story, and do you think she learns her lesson? Consider the them we have discussed and provide textual evidence to support your answer. You must use the RACE strategy to construct your response. The cost of 9 scarves is $56.25. What is the unit price? - There is virtually no ability to limit the actions of the government. - These governments tend to be authoritarian or tyrannical in nature. - Individual rights and freedoms are curbed. - Citizens are expected to display total obedience to the rulers and the ruler's decisions. What type of government does these (Above) terms describe?A. Republican governmentB. Communist governmentC. Limited governmentD. Unlimited government PORTFOLIO ITEM: CREATING A BLOG!!! PLEASE HELP. my dog is trying to eat my fooood rachel is 1.35 m tall her friend pita is 179 cm tall who is taller and by how much give your answer in centimeters 2 numbers that when added equals 36 but when multiplied equals -12 (-3, -14) and (0, -9) En la tabla 1.8 se presentan los puntos de ebullicin aproximados de algunos elementos de la tabla periodica flor -180 hidrogeno -253 argn -186 helio -269 nitrgeno -196 nen -246 Cul es el elemento qumico con el mayor punto de ebullicin? y con el menor? Find the area of the shaded region. 4cm5cmstep by step plz please help due in 5 minutes I know its a long question but I will give brainliest. Felix said quadrilateral ABCD is a parallelogram becauseBE = DE. What was his error? pls pls help me! Trousers bought 1400 dollars with 20% discount. How much is the original price? Whats 4x+2=2(x+6) ?Just want to see your answers