Question

In: Computer Science

Python please! Create one program to include all 10 elements: Create a function that prints a...

Python please!

Create one program to include all 10 elements:

  • Create a function that prints a sentence passed to the function as parameter. On the next line, print the same sentence without the 1st and the last character, use string slicing.
  • Use the following sentence:
    • This is the sentence.
  • Given a string:
  • This string was copied in an article.
  • Replace the relevant words to read as follows:
  • This string was discovered in the article xyz.
  • Given a string:
  • This string is highly reversible.
  • Write the code to reverse the string. Use 2 different ways of doing this.
  • Given a string:
  • This string has a hidden message in it.
  • Write the code that checks to see the word: hidden
  • is in the sentence.
  • Write the code that checks to see the word: not
  • is not in the sentence.
  • What is the size of the following string?
  • This string is saying 'I am not sure what is the my size'
  • Write the code for it and print the size.
  • Given the sentence below:
  • This sentence needs to get rid of the word delete
  • Delete the words: to get rid of
  • from the sentence and print it.
  • Create a sentence and the use the following functions to manipulate the sentence.
  • strip()
  • lstrip()
  • rstrip()
  • Create a function that accepts 2 parameters.
  • Parameter one is a single printable character such as '='.
  • Parameter two is a number not more than 80.
  • The function will return a string that is the character supplied strung together n number of times.
  • example. print(myLineFunction('%', 20)) which should print: %%%% up to 20 %s
  • Create a string and test its start and end character/s using the
  • string.startswith() and string.endswith() functions.

Create a string of several word and convert it to a list using:

string.split(), use the space to split the words.

Convert the resulting list to the original string using ' '.join(the list)

Solutions

Expert Solution

Program Code Screenshot:

Sample output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Program to copy:

def print_sentence(s):
print("The sentence is :",s)#prints the sentence passed to it
print("The sentence without first and last characters:",s[1:-1])

print_sentence("This is the sentence")

s="This string was copied in an article"
s=s.replace("copied","discovered")#replace the words and store the string back to s
s=s.replace("an","the")
s=s.replace("article","article xyz")

print(s)

s="This string is highly reversible"
s=s[::-1]#method 1 to reverse a string
print("The reversed string is:",s)

s="This string is highly reversible"
s="".join(reversed(s))#method 2 to reversed a string
print("The reversed string is:",s)


s="This string has a hidden message in it."
if "hidden" in s:#check if 'hidden' is present in string
print("The word hidden is present in the string")
else:
print("The word hidden is not present in the string")

s="I am not sure what is the my size"
print("The length of the string: ",s," is ",len(s))#print length of string

s="This sentence needs to get rid of the word"
print("The sentence is:",s)
s=s.replace("to get rid of","")#replace the words
print("After deleting the word from the sentence:",s)

s=" This is a sentence "
print("The sentence after using lstrip() is:",s.lstrip())#removes the left side spaces

s=" This is a sentence "
print("The sentence after using rstrip() is:",s.rstrip())#removes the right side spaces


s=" This is a sentence "
print("The sentence after using strip() is:",s.strip())#removes all the left and right side spaces

def myLineFunction(c,n):
s=c*n
return "The string is:"+s

print(myLineFunction('%', 20))
s="This is a new string"
if s.startswith("This"):
print("The string starts with 'This'")

if s.endswith("ring"):
print("The string ends with 'ring'")

s="This string is converted to list of words"
l=s.split()#split the string to words
print("The list of words:",l)
print("Converting back to string:")
print(' '.join(l))#join the list of words back to string


Related Solutions

Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
python Write a program that prints your name 100 times to the screen. Write a function...
python Write a program that prints your name 100 times to the screen. Write a function that takes a string s and an integer n as parameters and prints the string s a total of n times (once per line). Write a for loop that prints all the integers from 3141 to 5926, skipping every other one. Write a for loop that prints every 5th integer from 5926 down to 3141. Write a program (using a for loop) to print...
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
write a python program, please. Create a program that uses the Gettysburg Address as input and...
write a python program, please. Create a program that uses the Gettysburg Address as input and outputs a list of tuples for every two words. For example: [('Four', 'score'),('and', 'seven'), ...].
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are...
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are multiples of 10, starting at 0 and ending at 100. Write a python program that computes the average of 10 random odd integers, ranging from 0 to 500. Write a python program that prints whatever the user enters, and stops when the user types “done”, using an infinite loop and a break statement. Same as number three but use a condition. The loop terminates...
Python Programcomplete theprocessString(string)function. This function takesin a string as a parameter and prints the...
Python Program complete theprocessString(string)function. This function takes in a string as a parameter and prints the average number of characters per word in each sentence in the string. Print the average character count per word for each sentence with 1 decimal precision(see test cases below).-Assume a sentence always ends with a period (.)or when the string ends. -Assume there is always a blank space character(" ")between each word. -Do not count the blank spaces between words or the periods as...
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an...
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an integer number. The function, which must be a value-returning function, returns 1 if the number is even or 0 if the number is odd. In the “main” function (i.e. def main()), capture the return value and print an appropriate message on screen (i.e. number is even or odd). Rubric: Correctly defined a value-returning function: 5 pts Correctly capture and use return value from a...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English...
Matlab program Create a function, when given a two-digit integer as input, prints the equivalent English phrase. For example, given 39, output thirty-nine. Limit the input numbers to be in the range 21 to 39.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT