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"

Respuesta :

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

Ver imagen 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

Ver imagen codiepienagoya