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...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out...
Write a program in PYTHON which: *Defines the following 5 functions: whoamI() This function prints out your name and PRINTS OUT any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one parameter, a number,...
Description of the Assignment: Write a Python program to create a deque and append few elements...
Description of the Assignment: Write a Python program to create a deque and append few elements to the left and right, then remove some elements from the left, right sides and reverse the deque. Please use the following comments in your python script: # ************************************************* # COP3375 # Student's full name ( <<< your name goes here) # Week 9: Assignment 1 # ************************************************* # Write your code below: # Create a deque # Print a deque # Append to...
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,
Use Python to solve: show all work 1) Write a program that prints out a deck...
Use Python to solve: show all work 1) Write a program that prints out a deck of cards, in the format specified below. (That is, the following should be the output of your code). 2 of hearts 2 of diamonds 2 of spades 2 of clubs 3 of hearts 3 of diamonds 3 of spades 3 of clubs 4 of hearts 4 of diamonds 4 of spades 4 of clubs Continue with 5,6,7.. ending with A of hearts A of...
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()
MATLAB Create a function that prints a string of perfect cubes between (m,n). Include any reasonable...
MATLAB Create a function that prints a string of perfect cubes between (m,n). Include any reasonable error statements such as decimals and negative numbers.
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'), ...].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT