Question

please help, language is python You’re creating a secret code to share with your friends such...

please help, language is python

You’re creating a secret code to share with your friends such that every word should be written with the second and last letters swapped.

Write a function called encode that receives a string (input) and prints out another string with the second and last letters swapped.

Example function calls:

encode(secret) # should print “the code for secret is stcree”

encode(city) # should print “the code for city is cyti”

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def encode(s):
    result = s
    if len(s) >= 2:
        result = s[:1] + s[-1] + s[2:-1] + s[1]
    print("the code for", s, "is", result)


encode("secret")
encode("city")

Add a comment
Know the answer?
Add Answer to:
please help, language is python You’re creating a secret code to share with your friends such...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Python 3.6 You’re creating a secret code to share with your friends such that every...

    Using Python 3.6 You’re creating a secret code to share with your friends such that every word should be written with the second and last letters swapped. Write a function called encode that receives a string (input) and prints out another string with the second and last letters swapped. Example function calls: encode(secret) # should print “the code for secret is stcree” encode(city) # should print “the code for city is cyti

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • Written in python programming for MyProLab :) Please use simple code Assume the availability of a...

    Written in python programming for MyProLab :) Please use simple code Assume the availability of a function called printStars. The function receives an integer value as an argument. If the argument is positive, the function prints (to standard output) the given number of asterisks. Thus, if printStars(8) is called, ******** (8 asterisks) will be printed. Assume further that the variable starCount has been declared and initialized with an integer value, possibly negative or zero. Write some code that does nothing...

  • ** Language Used : Python ** PART 2 : Create a list of unique words This...

    ** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...

  • USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3...

    USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3 numbers, and print the sum of those numbers to the console 16. Write code that opens a file named words.txt containing an essay, and the prints out the SECOND word in the file to the console

  • Hi, I need help writing a code for this. The language is python 3, and we...

    Hi, I need help writing a code for this. The language is python 3, and we cannot use things like break, continue, exit(), lambda, map, filter, raise, try, except, and assert in our code. Thank you! We must write a function called "binary_to_decimal(binary_number)" that takes a string for a binary number and output the decimal integer for that number. The solution, aka the code, MUST contain a for loop of this form (power is an integer variable you define earlier):...

  • PLEASE DO THIS IN PYTHON!! 1.) Goal: Become familiar with The Python Interpreter and IDLE. Use...

    PLEASE DO THIS IN PYTHON!! 1.) Goal: Become familiar with The Python Interpreter and IDLE. Use IDLE to type, compile, and run (execute) the following programs. Name and save each program using the class name. Save all programs in one folder, call it Lab1-Practices. Save all programs for future reference as they illustrate some programming features and syntax that you may use in other labs and assignments. ================================== Program CountDown.py =================================== # Program CountDown.py # Demonstrate how to print to...

  • Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function...

    Language: Python Function name : findwaldo Parameters : string Returns: int Description: Write a recursive function that takes in a string containing some combination of letters, numbers, and spaces, and return the starting index of the first instance of “waldo” contained in that string. If the string does not contain “waldo”, return -1. This function IS case sensitive, so “waldo” is not the same as “WALDO”. Code using string functions such as .index() and .find() that oversimplify the problem will...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • Hi, I need some help finishing the last part of this Python 1 code. The last...

    Hi, I need some help finishing the last part of this Python 1 code. The last few functions are incomplete. Thank you. The instructions were: The program has three functions in it. I’ve written all of break_into_list_of_words()--DO NOT CHANGE THIS ONE. All it does is break the very long poem into a list of individual words. Some of what it's doing will not make much sense to you until we get to the strings chapter, and that's fine--that's part of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT