169k views
4 votes
Create a function called "strip_r_o" that takes in a STRING and strips all the Rs and Os from the string. Also use a FOR loop in you program to check each letter of the STRING

Python

User Sveitser
by
5.3k points

1 Answer

4 votes

Answer:

The program is as follows (Take note of the comments and see attachment)

#Start of Program

def strip_r_o(word): #Declare Function strip_r_o

resultt = "" #initialize resultt to empty string

for i in range(len(word)): #Iterate from first character of input string to the last

if (not word[i] == "R") and (not word[i] == "O"): #Check if current character is not R and O

resultt = resultt + word[i] #if condition is true, add character to resultt

print(resultt) #Print string after character has been removed

#End of Function

Word = input("Enter a string: ") #Prompt user for input

strip_r_o(Word) #Call strip_r_o function

#End of Program

Step-by-step explanation:

The program starts and end with a comment

Line 2 of the program declares function strip_r_o

Line 3 initializes a string variable resultt to an empty string

Line 4 iterates from first character of input string to the last

Line 5 checks each character for O or R

If true, line 6 is executed by removing O or R from the input string and saving what's left in variable resultt

Line 7 prints the end result after O and R have been removed from the input string

Line 8 is a comment

Line 9 prompts user for an input string

Line 10 calls the strip_r_o function

Create a function called "strip_r_o" that takes in a STRING and strips all-example-1
User Jackbijou
by
5.1k points