Missing Something


#1



4. Redacted! Lesson


Earlier, I had some problems creating the code for this, but that's been solved after having a peak at another person's variation of this.

It seemingly behaves how I want it to. It's just not redacting the word I want it to redact multiple times. It stops redacting after the first word that needs to be redacted.

I know, i'm missing a string of code, but I don't know what. Can someone help me with this?


puts "Text to search through : " 
text = gets.chomp
puts "Words to redact : " 
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    if word != redact
    print word + " "
    else
        print "REDACTED"
end
end

Replace this line with your code.


#2

I've recently discovered that after trying different words and sentence combinations for it to redact, I notice that it redacts words how I want it to. (sort of) it just puts REDACTED right in front of another word. It does this : What is life? It is the Chicken. To Redact : is

OUTCOME : What REDACTEDlife? It REDACTEDthe Chicken.

That could possibly be messing it up. And how can I fix my code to where it won't do that?


#3

By adding a single space to "REDACTED ".


#4

Thanks. I needed that.


#5

Okay, now it's working how it's supposed to, but it won't accept my code as an answer. Can you guys see anything wrong with it?

puts "Text to search through : " 
text = gets.chomp
puts "Words to redact : " 
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    if word != redact
    print word + " "
    else
        print "REDACTED "
end
end


#6

I don't see anything wrong with your code, and as you say, it works as expected. Perhaps it just needs to be refreshed and submitted again?


#7

I've tried refreshing and messing with my code and it still won't accept it. I don't know what's going on.


#8

Maybe change up the order in your conditional:

if word == redact:
    print "REDACTED "
else:
    print word + " "
end

#9

That doesn't seem to work either. Yours seems to just cause my code to not work at all. It's strange. It just won't accept my code as an answer. And I don't know why.


#10

Because my code is Python, not Ruby. My bad. Please remove the colons.


#11

This is so frustrating! What am I doing wrong? I've been stuck on this lesson for like a week now and I still don't know what's causing it to not accept it as an answer. I mean, it works how it's supposed to doesn't it? Maybe I need to somehow make it redact the words being printed to the console too?

Current code below + output and error(?).

puts "Text to search through : " 
text = gets.chomp
puts "Words to redact : " 
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    if word == redact
    print "REDACTED "
else
    print word + " "
end
end

INPUT : Text to search through :
is is is
Words to redact :
is
OUTPUT : REDACTED REDACTED REDACTED ["is", "is", "is"]
Error message : Oops, try again. It looks like you didn't print each word from the user's text to the console.

Like I said before, am I missing something?


#12

Your code works and passes for me. Could it be the browser? Do you have an alternate you can try this in, like Firefox or Chrome?


#13

Just tried it in Firefox, and Chrome is what i'm using. Same Result. :confused:


#14

Try using a phrase that does not have the last word redacted?

Try removing white space from before colons?

I'm out of ideas since everything I try to do works so it's difficult to pin down a problem.


#15

For which of the six exercises is this being submitted? Each one has its own submission correctness test (SCT) with different requirements for passing. For the final exercise, anything passes.


#16

@drakentech ,

On my machine, your code from this post passes for Exercise 5: Control Flow Know-How. It does not pass for Exercise 4: Redacted!, because for that exercise, we should just output the same words that are input, without redacting anything.

This modified version of your code does pass Exercise 4: Redacted! on my machine, because it does output each word, as is ...

puts "Text to search through : " 
text = gets.chomp
puts "Words to redact : " 
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    print word
end

#17

@appylpye, that was going to be my next question, but I decided to let someone else jump in. Thanks for your input.


Strange error in Redacted 5/6
#18

Oh, I was getting the notion that it was wanting me to also redact the stuff. Thanks for pointing that out. It works now.


#19

For the fifth exercise, redact the stuff, but not for the fourth one, even though that exercise is named Redacted!.


#21