115k views
5 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

User Casanova
by
4.6k points

1 Answer

0 votes

Answer:

Following are the code to this question:

def strip_r_o(val): #Defining a method strip_r_o that takes a parameter

r = "" #defining a string variable

for x in range(len(val)): # declaring a for loop that reads input value

if (not val[x] == "R") and (not val[x] == "O"): #declaring if block to check first character is not R and O

r=r+val[x] #add character values

print(r) #Print calculated value

val= input("Enter a string: ") #input value from user end

strip_r_o(val) #Calling strip_r_o method

Output:

Enter a string: Raju

a

aj

aju

Step-by-step explanation:

Following are the description of the above python code:

  • In the above code, a method "strip_r_o" is declared in which "val" variable is passed as a parameter, inside the method a string variable "r" is declared, that uses the for loop to removes "R and O" from the string value and store and print its values.
  • In the next step, val variable is declared, that the input value from the user and call the "strip_r_o" method value.
User Leander Moesinger
by
4.8k points