Westonci.ca offers quick and accurate answers to your questions. Join our community and get the insights you need today. Connect with professionals ready to provide precise answers to your questions on our comprehensive Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

PYTHON 7.1.6: Sandwich Sandwiches (codehs)

In this exercise, write a function called sandwich which takes a 3 letter string. Your function should return the letters that are at the beginning and end of the string.

For example,

sandwich("pbj")
# => "pj"
sandwich("blt")
# => "bt"


Sagot :

I've included my code below. Best of luck.

View image Cytokine

Following are the Python program to calculate the string value:

Program Explanation:

  • Defining a method "sandwich" that takes string variable "x" in parameter.
  • Inside the method, a return keyword is used that removes the middle string value.
  • Outside the method, a print method is used that calls the "sandwich" method which accepts a string value in it and prints its return value.

Program:

def sandwich(x):#defining a method sandwich that takes string variable x in parameter

return x[0]+ x[-1]#using return keyword that remove middle string value

print(sandwich("pbj"))#calling method and print its return value

print(sandwich("blt"))#calling method and print its return value

Output:

Please find the attached file.

Learn more:

brainly.com/question/8647085

View image codiepienagoya